Usage

The Decision API provides REST endpoints that enable you to retrieve feature flags and campaigns based on visitor context. This guide covers the three core endpoints with practical examples.

Overview

The Decision API uses a visitor-centric model where decisions are made based on:

  • Visitor ID: A unique identifier for the user

  • Context: Key-value pairs describing the visitor (device type, location, user attributes, etc.)

The API returns personalized campaigns (A/B tests, feature flags) and modifications (variations, flag values) tailored to each visitor.


Get Decision

The /v2/campaigns endpoint retrieves all active campaigns and their variations for a specific visitor.

Concept

When you send a visitor's ID and context, the Decision API:

  1. Fetches your configuration from FE&R

  2. Evaluates targeting rules against the visitor's context

  3. Assigns the visitor to appropriate campaigns and variations

  4. Returns the list of campaigns with their modifications

This is the primary endpoint for getting all decisions in one call.

Endpoint

Request Body

Parameters:

  • visitor_id (string, required): Unique identifier for the visitor

  • context (object, optional): Key-value pairs describing the visitor

  • trigger_hit (boolean, optional): If true, automatically sends an activation hit (default: false)

Example: Basic Request

Response

Response Structure:

  • visitorId: The visitor ID from the request

  • campaigns: Array of active campaigns for this visitor

    • id: Campaign identifier

    • variationGroupId: Variation group identifier

    • variationGroupName: Variation group name

    • variation.id: Assigned variation identifier

    • variation.modifications.type: Modification type

    • variation.modifications.value: Key-value pairs with configuration values

    • variation.reference: true if this is the control group (original)

Example: With Context-Based Targeting

Example: With Automatic Activation

When trigger_hit: true, the API automatically sends activation events for all returned campaigns.


Get Feature Flag

The /v2/flags endpoint allows you to retrieves feature flags in a simplified, developer-friendly format.

Concept

Feature flags are part of the data included in campaigns and are specifically designed for:

  • Enabling/disabling features

  • Configuration management

  • Progressive rollouts

This endpoint transforms campaign modifications into a flat key-value structure, making it easier to check flags in your code.

Endpoint

Request Body

Parameters:

  • visitor_id (string, required): Unique identifier for the visitor

  • context (object, optional): Key-value pairs describing the visitor

Example: Basic Request

Response

Response Structure:

  • Each flag key maps to an object containing:

    • value: The flag value (can be any JSON type)

    • metadata: Information about the campaign and variation

      • campaignId: Campaign identifier

      • campaignName: Human-readable campaign name

      • slug: Campaign slug (if set)

      • type: Campaign type (ab, toggle, etc.)

      • variationGroupId: Variation group identifier

      • variationGroupName: Variation group name

      • variationId: Assigned variation identifier

      • variationName: Variation name

      • reference: true if this is the control/reference variation

Example: Multi-Platform Context

Example: Anonymous Visitor


Activate a Campaign

The /v2/activate endpoint sends an activation event when a visitor is exposed to a campaign variation.

Concept

Activation tracking is crucial for analytics and attribution. You should activate a campaign when:

  • A visitor sees the variation (impression tracking)

  • A feature is actually used (not just loaded)

  • You want to track which users experienced a variation

Important: Only activate when the user is genuinely exposed to the experience. Don't activate on page load if the feature isn't visible.

Endpoint

Request Body

Parameters:

  • vid (string, required): Visitor ID

  • cid (string, required): Environment ID (your FE&R environment ID)

  • caid (string, required): Variation Group ID (from /v2/campaigns response: variationGroupId)

  • vaid (string, required): Variation ID (from /v2/campaigns response: variation.id)

  • aid (string, optional): Anonymous ID if different from visitor ID

Example: Basic Activation

Response

Status Code: 204 No Content

The activate endpoint returns an empty response body with a 204 status code on success.

Example: Activate Multiple Campaigns

Default settings:

  • Batch size: 50 hits

  • Batching window: 30 seconds

  • Hits are sent when either condition is met:

    • Batch reaches 50 hits, OR

    • 30 seconds have passed since last send

Batch Activate

You can activate multiple campaigns in a single HTTP request using the batch format:

Batch Format:

  • cid (string, required): Environment ID - applies to all items in the batch

  • batch (array, required): Array of activation objects, each containing:

    • vid (string, required): Visitor ID

    • caid (string, required): Variation Group ID

    • vaid (string, required): Variation ID

    • aid (string, optional): Anonymous ID

Benefits of batching:

  • Reduces HTTP overhead (1 request instead of N)

  • Atomic operation - all activations processed together

  • Better performance for multiple simultaneous activations

Separate Requests

When to Activate

Do activate when:

  • User sees a variation on their screen

  • Feature is rendered/displayed

  • User interacts with a feature

Don't activate when:

  • Just fetching configuration

  • Preloading data

  • User hasn't seen the variation yet

Best Practices

1. Use Meaningful Visitor IDs

2. Provide Rich Context

3. Activate Only on Exposure


Custom Visitor Cache Assignment Connector

The Decision API supports custom visitor cache assignment connectors to persist visitor assignments when using advanced features:

  • Experience Continuity (XPC): Keep visitors in the same variation across sessions

  • 1 Visitor 1 Test (1v1t): Ensure each visitor is assigned to only one campaign

  • Dynamic Allocation: Support traffic allocation changes

By default, the Decision API uses an empty connector (no persistence). For production use with these features, configure one of the available cache types. The Self-Hosted Decision API provides 4 cache systems to store and retrieve visitor assignments to allow traffic allocation changes for live use cases:

  • in memory: the assignments are stored in memory

  • local: the assignments are stored in a local file using a key/value database

  • redis: the assignments are stored in a redis server

  • dynamo: the assignments are stored in an AWS DynamoDB table

If you want to use another cache management system, you still can, but you will need to create a Go application that runs the Decision API package, and implement your own visitor assignment interface.

Here is an example of how you can do that:

Metrics endpoint

On top of the usual endpoints, the open source Decision API also exposes a /v2/metrics endpoint, which can be used to monitor the API performance, errors and response time. The metrics output format looks like:

Swagger endpoint

The Decision API also provides a /v2/swagger/ endpoint with interactive Swagger UI documentation where you can explore all available endpoints and test API calls directly from your browser.

Last updated

Was this helpful?