---
title: REST API cookbook
slug: feature-experimentation/api/hxln-rest-api-cookbook
docTags: 
createdAt: 2026-08-05T20:40:17.712Z
---

## Prerequisites

- Download [Visual Studio Code](https://code.visualstudio.com/download).
- Install the [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) extension from the Visual Studio marketplace.

## Get your Optimizely API personal access token

Follow [Generate tokens and use the REST APIs](docId\:pQfa5KPTbmy6crey-nsrd) 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:

```json
{
    "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"
        }  
    }
}
```

:::Paragraph{indent="1"}
Replace the following in the code:
:::

:::Paragraph{listStyleType="disc" indent="2"}
`YOUR_TOKEN` – With your personal access token.
:::

:::Paragraph{listStyleType="disc" indent="2"}
`YOUR_PROJECT_ID` – With your project ID.
:::

:::BlockQuote
📘 NoteYou can find your project ID in the URL from the [Optimizely application homepage](https://app.optimizely.com), 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](docId\:uu6zmA5Bkeqsq84hqUmL3).
:::

See the [Visual Studio Code REST Client GitHub repository](https://github.com/Huachao/vscode-restclient) 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

:::Iframe{code="<Recipe slug=&#x22;1-create-a-flag-and-variables&#x22; title=&#x22;1. Create a flag and variables&#x22; />" iframeHeight="0"}

:::

`create-a-flag-and-variables.rest`

:::Iframe{code="<Recipe slug=&#x22;2-create-variations&#x22; title=&#x22;2. Create variations&#x22; />"}

:::

`create-variations.rest`

:::Iframe{code="<Recipe slug=&#x22;3-create-events&#x22; title=&#x22;3. Create events&#x22; />"}

:::

`create-events.rest`

:::Iframe{code="<Recipe slug=&#x22;4-create-attributes&#x22; title=&#x22;4. Create attributes&#x22; />"}

:::

`create-attributes.rest`

:::Iframe{code="<Recipe slug=&#x22;5-create-audiences&#x22; title=&#x22;5. Create audiences&#x22; />"}

:::

`create-audiences.rest`

:::Iframe{code="<Recipe slug=&#x22;6-create-experiment&#x22; title=&#x22;6. Create experiment&#x22; />"}

:::

`create-experiment.rest`

:::Iframe{code="<Recipe slug=&#x22;7-launch-experiment&#x22; title=&#x22;7. Launch experiment&#x22; />"}

:::

`launch-experiment.rest`

:::Iframe{code="<Recipe slug=&#x22;8-conclude-experiment&#x22; title=&#x22;8. Conclude experiment&#x22; />"}

:::

`conclude-experiment.rest`

:::Iframe{code="<Recipe slug=&#x22;9-analyze-results&#x22; title=&#x22;9. Analyze results&#x22; />"}

:::

`analyze-results.rest`

:::hint{type="info"}
**Note**
See the [Visual Studio's REST Client's documentation on usage](https://marketplace.visualstudio.com/items?itemName=humao.rest-client#usage) for information on how to send requests using the REST Client extension.
:::
