REST API cookbook
Prerequisites
- Download Visual Studio Code.
- Install the REST Client extension from the Visual Studio marketplace.
Get your Optimizely API personal access token
Follow Generate tokens and use the REST APIsGenerate tokens and use the REST APIs to get a personal access token to the Optimizely APIs.
Configure the Visual Studio Code REST Client
Create environment variables for the Optimizely API endpoints and add your personal access token to reuse it across API requests.
- In Visual Studio Code, create a directory named .vscode in the root of your project.
- In this directory, create a file named settings.json and copy and paste the following code into the file:
{
"rest-client.environmentVariables": {
"$shared": {
"flagsUrl": "https://api.optimizely.com/flags/v1",
"baseUrl": "https://api.optimizely.com/v2",
"token": "Bearer YOUR_TOKEN",
"projectId": "YOUR_PROJECT_ID",
"flagKey": "inventory_on_pdp",
"environment": "production"
}
}
}Replace the following in the code:
- YOUR_TOKEN – With your personal access token.
- YOUR_PROJECT_ID – With your project ID.
See the Visual Studio Code REST Client GitHub repository for information on adding environment variables.
Run recipes
After configuring Visual Studio Code, you can use the following recipes to create an example A/B test using the Feature Experimentation REST API endpoints.
For each recipe:
- Create a {recipe-name}.rest file in your project. For example, create-a-flag-and-variables.rest.
- Copy and paste the recipe in the .rest file.
- Click Send Request above each request or press Ctrl + Alt + R (Cmd + Alt + R for macOS).
Recipes
create-a-flag-and-variables.rest
create-variations.rest
create-events.rest
create-attributes.rest
create-audiences.rest
create-experiment.rest
launch-experiment.rest
conclude-experiment.rest
analyze-results.rest
Note See the Visual Studio's REST Client's documentation on usage for information on how to send requests using the REST Client extension.