Create a flag and variables
// -------------------------------------------------------------------------- //
// Create a feature flag and flag variables. //
// -------------------------------------------------------------------------- //
POST {{flagsUrl}}/projects/{{projectId}}/flags
Content-Type: application/json
Authorization: {{token}}
{
"key": "inventory_on_pdp",
"name": "Inventory on PDP",
"description": "Flag to either show or hide inventory on the product detail page.",
"variable_definitions": {
"show_amounts": {
"key": "show_amounts",
"type": "boolean",
"default_value": "false",
"description": "If inventory is shown, this variable controls what is displayed: available/unavailable vs the actual inventory amount."
},
"text_color": {
"key": "text_color",
"type": "string",
"default_value": "green",
"description": "The color of the text displaying the inventory."
},
"low_stock_threshold": {
"key": "low_stock_threshold",
"type": "integer",
"default_value": "0",
"description": "The threshold quantity remaining to show a low stock message. Setting this to 0 results in not displaying the low stock message."
},
"low_stock_message": {
"key": "low_stock_message",
"type": "string",
"default_value": "Low Stock - Act Quick",
"description": "The Low Stock message to display if low_stock_threshold is set to a number greater than 0."
}
}
}Create a flag with four variables using the Create flag API endpoint.
Prerequisite
Before running this request, you must follow the instructions to configure your REST API cookbook.
Create file
Create a file named create-a-flag-and-variables.rest and copy and paste the recipe into the file.
Configure the API call
{{flagsUrl}}, {{projectId}}, 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
Content-Type: application/json
Authorization: {{token}}Configure the flag
Creates a flag with the following info:
- key – inventory_on_pdp
- name – Inventory on PDP
- description – Flag to show or hide inventory on the product detail page (PDP).
This corresponds to the following page in the UI:
"key": "inventory_on_pdp",
"name": "Inventory on PDP",
"description": "Flag to either show or hide inventory on the product detail page.",Create flag variables
Flag variables let you remotely configure your flag. Instead of hard-coding and updating your variables by re-deploying, you can group them in a flag variation and update them remotely in the UI or through the REST API.
Create show_amounts variable
Adds a variable named show_amounts that is a Boolean with a default value of false to the inventory_on_pdp flag. The show_amounts variable controls what is displayed for the inventory.
Corresponds to the following in the UI:
"show_amounts": {
"key": "show_amounts",
"type": "boolean",
"default_value": "false",
"description": "If inventory is shown, this variable controls what is displayed: available/unavailable vs the actual inventory amount."
},Create text_color variable
Adds a variable named text_color that is a String and has the default value of green to the inventory_on_pdp flag. The text_color variable sets the color of the text displaying the inventory.
Corresponds to the following in the UI:
"text_color": {
"key": "text_color",
"type": "string",
"default_value": "green",
"description": "The color of the text displaying the inventory."
},Create low_stock_threshold variable
Adds a variable named low_stock_threshold that is an Integer with a default value of 0 to the inventory_on_pdp flag. The low_stock_threshold variable is the threshold quantity remaining to show a low stock message.
Corresponds to the following in the UI:
"low_stock_threshold": {
"key": "low_stock_threshold",
"type": "integer",
"default_value": "0",
"description": "The threshold quantity remaining to show a low stock message. Setting this to 0 results in not displaying the low stock message."
},Create low_stock_message variable
Adds a variable named low_stock_message that is a String with a default value of Low Stock - Act Quick to the inventory_on_pdp flag. The low_stock_message variable is the message displayed if the low_stock_threshold variable is set to a number greater than 0.
Corresponds to the following in the UI:
"low_stock_message": {
"key": "low_stock_message",
"type": "string",
"default_value": "Low Stock - Act Quick",
"description": "The Low Stock message to display if low_stock_threshold is set to a number greater than 0."
}Send request
Click Send Request in Visual Studio Code. See the REST Client's documentation on usage for information on how to send requests using the REST Client extension.