Quickstart for Agent
Provides steps on how to quickly get started with Optimizely Agent using Node and explores Agent's REST APIs.
Running locally using Node
Watch this 4-minute video on implementing Optimizely Agent with example microservices or follow the instructions to Install Optimizely Agent on your preferred operating system.
Evaluating Agent REST APIs
Note
The Agent REST APIs are defined through OpenAPI (formerly known as Swagger and can be found on localhost or in our developer documentation. The following examples use Python code for brevity, but can be expanded for any programming language.
Start an HTTP session
Each request made into Optimizely Agent is in the context of an Optimizely SDK key. SDK keys map API requests to a specific Optimizely Feature Experimentation Project and Environment. We can set up a global request header by using the requests.Session
object.
import requests
s = requests.Session()
s.headers.update({'X-Optimizely-SDK-Key': '<YOUR_SDK_KEY>'})
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 you have a different SDK key for each environment.
Important
️You must start an HTTP session. Future examples will assume this session is being maintained.
Get current environment configuration
The /config endpoint returns a manifest of the current working environment.
resp = s.get('http://localhost:8080/v1/config')
env = resp.json()
for key in env['featuresMap']:
print(key)
Run a feature flag rule
The /decide?keys={keys} endpoint decides whether to enable a feature flag or flags for a given user. You can decide multiple flags with this syntax: /v1/decide?keys=flagA&keys=flagB
. Optimizely will provide a userId
through the request body. The API evaluates the userId
to determine which flag rule and flag variation the user buckets into.
Rule types include:
- A/B tests – Flag variations are measured against one another.
- Targeted delivery – Progressively make the flag available to the selected audience.
This endpoint returns an array of OptimizelyDecision
objects, which contains information about the flag and rule the user was bucketed into.
params = { "keys": "my-feature-flag" }
payload = {
"userId": "test-user",
"userAttributes": {
"attr1": "sample-attribute-1",
"attr2": "sample-attribute-2"
}
}
resp = s.post(url = 'http://localhost:8080/v1/decide', params=params, json=payload)
print(resp.json())
The decide API is a POST to signal to the caller that there are side-effects. Namely, this endpoint results in a "decision" event sent to Optimizely analytics for the purpose of analyzing A/B test results. By default a "decision" is not sent if the feature flag is part of a targeted delivery.
Updated 10 months ago