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
Dev guide

Use Optimizely Agent

Optimizely Agent provides REST APIs that enable running feature flag rules, such as A/B tests and targeted flag deliveries.

Optimizely Agent provides equivalent functionality to all our regular, language-specific SDKs. At Optimizely Agent's core is the Optimizely Go SDK.

Running feature flag rules

The Decide endpoint buckets a user into a feature flag variation as part of a flag rule. It chooses between multiple enabled or one disabled variation for a flag. Flag rules include A/B tests and targeted feature flag deliveries. To run a flag rule, use the following:

POST /v1/decide?keys={flagKey}

In the request application/json body, include the userId and any decideOptions. The full request looks like

curl --location --request POST 'http://localhost:8080/v1/decide?keys=YOUR_FLAG_1&keys=YOUR_FLAG_2'
--header 'X-Optimizely-SDK-Key: YOUR_SDK_KEY'
--header 'Accept: text/event-stream'
--header 'Content-Type: application/json'
--data-raw '{
"decideOptions": [
],
"userId": "string",
"userAttributes": {
   "additionalProp1": {}
  }
}'

This returns an array of OptimizelyDecision objects that contain all the information you need to run your flag rule, such as:

  • The decision to bucket this user into an enabled or disabled feature flag variation.
  • Any corresponding feature flag variable values.

For example:

{
	"userContext": {
        "UserId": "test-user",
        "Attributes": {
            "logged-in": true,
            "location": "usa"
        }
    },
    "flagKey": "my-feature-flag",
    "ruleKey": "my-a-b-test",
	  "enabled": false,
    "variationKey": "control_variation"
	"variables": {
		"my-var-1": "cust-val-default-1",
		"my-var-2": "cust-va1-default-2"
	},
    "reasons": []
}

The response is determined by the A/B tests and targeted deliveries defined for the supplied feature key, following the same rules as any Optimizely Feature Experimentation SDK.

🚧

Important

If the user is bucketed into an A/B test, this endpoint dispatches a decision event.

Authentication

To authenticate, pass your SDK key as a header named X-Optimizely-SDK-Key in your API calls to Optimizely Agent. You can find your SDK key in app.optimizely.com under Settings > Environments > SDK Key. Remember each environment has its own SDK key.

Get all decisions

  • To get all feature flag decisions for a visitor in a single request, omit the feature flag parameter:
    POST /v1/decide

  • To get decisions for multiple keys, specify multiple keys parameters, for example:
    keys=flag_key_1&keys=flag_key_2

  • To receive only the enabled feature flags for a visitor use a decide option in the application/json request body:

--header 'Content-Type: application/json' \
--data-raw '{
   "userId": "test-user"
   "decideOptions": [
      "ENABLED_FLAGS_ONLY"
   ]
}'

Track conversions

To track events, use the tracking endpoint:

POST /v1/track?eventKey={eventKey}

There is no response body for successful conversion event requests.

API reference

For more details on Optimizely Agent's APIs, see the complete Agent API Reference.