Get started with REST API

This tutorial lets you get started in your development efforts to use Optimizely API (2.0). This sample demonstrates how to programmatically:

  • set up a developer account and obtain an access token
  • use that token to invoke your first REST request

Create a free account

If you don't have an Optimizely account already, sign up for an Optimizely Rollouts account. This account will give you free access to Optimizely's APIs.

Generate a token

To use our REST API you must obtain a token:

  1. Access your developer account at app.optimizely.com. Once logged in, the dashboard is displayed.
  2. Click Profile on the bottom left-hand corner of the navigation tree.
  3. Select the API Access tab.
  4. Click Generate New Token.
  5. Enter a name for the new token on the popup and click Create. The website will redirect to the dashboard.
  6. Copy the token value from the Token column on the dashboard.

Make your first API call

In this section, you will invoke the List Projects endpoint to obtain a list of projects.

To use the REST API, you must include a request header called Authorization, set it to specify a Bearer token, and include the access token generated above.

In the following example, replace {personal_token} with the access token that you generated above and then execute the command using a terminal window:

curl -H "Authorization: Bearer {personal_token}" "https://api.optimizely.com/v2/projects"

The response contains a collection listing all of your projects:

[
  {
    "name": "Test Project",
    "confidence_threshold": 0.9,
    "dcp_service_id": 121234,
    "description": "Project for user sign up flow",
    "platform": "web",
    "sdks": [
      "android"
    ],
    "status": "active",
    "web_snippet": {
      "enable_force_variation": false,
      "exclude_disabled_experiments": false,
      "exclude_names": true,
      "include_jquery": true,
      "ip_anonymization": false,
      "ip_filter": "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
      "library": "jquery-1.11.3-trim",
      "project_javascript": "alert(\"Active Experiment\")",
      "code_revision": 0,
      "js_file_size": 63495
    },
    "account_id": 12345,
    "created": "2018-05-11T17:59:51.753Z",
    "id": 1000,
    "is_classic": true,
    "last_modified": "2018-05-11T17:59:51.753Z",
    "socket_token": "AABBCCDD~123456789"
  }
]

Start building

After performing the steps above, you can start building an application with Optimizely Web Experimentation See Optimizely API (2.0) for information about all of our supported endpoints.

For a more in-depth tutorial illustrating how to consume our REST APIs using Python, see our Optimizely Feature Experimentation REST Customer example that walks you through all of the endpoints required to construct an Experiment using Python scripts. You can also download our Postman collection to experiment with the APIs using Postman.

Questions about using the REST API? Submit a ticket to the developer support team.