Steps to set up Visual Studio Code as a REST client to make requests to the Optimizely APIs. After set up, you can use Recipes to run common REST API calls.
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 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 {{yourToken}}", "projectId": "{{yourProjectId}}", "flagKey": "inventory_on_pdp", "environment": "production" } } }
Replace:
{{token}}
โ With your personal access token.{{yourProjectId}}
โ With your project ID.
Note
You can find your project ID in the URL from the Optimizely application homepage, for example,
https://app.optimizely.com/v2/projects/{{your project ID}}/flags/list
).Or find your project ID on the API Values page in the Optimizely application.
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 REST Client's documentation on usage for information on how to send requests using the REST Client extension.