Create variations
// -------------------------------------------------------------------------- //
// Create variations. //
// -------------------------------------------------------------------------- //
// ------------------------ On Hide Amounts Variation ----------------------- //
POST {{flagsUrl}}/projects/{{projectId}}/flags/{{flagKey}}/variations
Content-Type: application/json
Authorization: {{token}}
{
"key": "on_hide_amounts",
"name": "On Hide Amounts",
"description": "Inventory is shown as available/unavailable, in the color green.",
"variables": {
"show_amounts": {
"value": "false"
},
"text_color": {
"value": "green"
}
}
}
###
// ------------------------ On Show Amounts Variation ----------------------- //
POST {{flagsUrl}}/projects/{{projectId}}/flags/{{flagKey}}/variations
Content-Type: application/json
Authorization: {{token}}
{
"key": "on_show_amounts",
"name": "On Show Amounts",
"description": "Inventory is shown with amounts, in the color green.",
"variables": {
"show_amounts": {
"value": "true"
},
"text_color": {
"value": "green"
}
}
}
###
// ------------------------ On Show Amounts Red Variation -----------------------
POST {{flagsUrl}}/projects/{{projectId}}/flags/{{flagKey}}/variations
Content-Type: application/json
Authorization: {{token}}
{
"key": "on_show_amounts_red",
"name": "On Show Amounts Red",
"description": "Inventory is shown with amounts, in the color red.",
"variables": {
"show_amounts": {
"value": "true"
},
"text_color": {
"value": "red"
}
}
}Create three example calls to the Create a New Variation API endpoint.
Prerequisite
Before running this request, you must follow the instructions to configure your REST API cookbook.
Create a file
Create a file named create-variations.rest and copy and paste the recipe into the file.
Configure API
{{flagsUrl}}, {{projectId}}, {{flagKey}}, and {{token}} are defined in the settings.json file. Ensure you have configured your Visual Studio Code project correctly. See Configure the Visual Studio Code REST Client.
POST {{flagsUrl}}/projects/{{projectId}}/flags/{{flagKey}}/variations
Content-Type: application/json
Authorization: {{token}}Default variation
The default (or control) variation of the product detail page (PDP). The default variation is the standard version of the website or feature that is displayed to users when no other variation is selected.
Create on hide amounts variation
Create an On Hide Amounts variation for a specific flag in a project.
Click Send Request in Visual Studio Code.
The On Hide Amounts variation contains two variables, show_amounts, set to false and text_color, set to green.
Flag variations are a reusable group of flag variable values that let you avoid hard coding values in your code.
This API call corresponds to the following in the UI:
{
"key": "on_hide_amounts",
"name": "On Hide Amounts",
"description": "Inventory is shown as available/unavailable, in the color green.",
"variables": {
"show_amounts": {
"value": "false"
},
"text_color": {
"value": "green"
}
}
}The ### delimiter
The REST Client extension delimits multiple requests using ###. See Main features in the REST Client documentation.
Create on show amounts variation
Create an On Show Amounts variation for a specific flag in a project. Click Send Request in Visual Studio Code.
The On Show Amounts variation contains two variables, show_amounts, set to true and text_color, set to green.
This API call corresponds to the following in the UI:
{
"key": "on_show_amounts",
"name": "On Show Amounts",
"description": "Inventory is shown with amounts, in the color green.",
"variables": {
"show_amounts": {
"value": "true"
},
"text_color": {
"value": "green"
}
}
}Create on show amounts red variation
Create an On Show Amounts Red variation for a specific flag in a project. Click Send Request in Visual Studio Code.
The On Show Amounts Red variation contains two variables, show_amounts, set to true and text_color, set to red.
This API call corresponds to the following in the UI:
{
"key": "on_show_amounts_red",
"name": "On Show Amounts Red",
"description": "Inventory is shown with amounts, in the color red.",
"variables": {
"show_amounts": {
"value": "true"
},
"text_color": {
"value": "red"
}
}
}