The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev guideRecipesAPI Reference
Dev guideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
API Reference

REST API cookbook

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

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.

  1. In Visual Studio Code, create a directory named .vscode in the root of your project.

  2. 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:

  1. Create a {recipe-name}.rest file in your project. For example, create-a-flag-and-variables.rest.
  2. Copy and paste the recipe in the .rest file.
  3. 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.