# Get Experiment Assignment

> REST reference for POST /experiments/assignments/{experiment_key}: the server-side variant assignment endpoint. Sticky on visitor_id, optionally records an impression.

Source: https://docs.oursprivacy.com/docs/reference/experiment-assignment

Return the server-side variant assignment for a visitor in a single A/B or multivariate experiment, identified by its experiment key. Bucketing is deterministic on `visitor_id` and is sticky across calls. Tracking an impression is the default. Pass `track_impression: false` to read without recording. The browser SDK and this endpoint converge on the same variant for the same visitor.

See the [Server-Side Experimentation](https://docs.oursprivacy.com/docs/experimentation/server-side) guide for end-to-end recipes.

## POST /experiments/assignments/{experiment_key}

Get Experiment Assignment

Return the server-side variant assignment for a visitor in a single A/B or multivariate experiment, identified by its experiment key. Bucketing is deterministic on `visitor_id` and is sticky across calls. Tracking an impression is the default — pass `track_impression: false` to read without recording. The browser SDK and this endpoint converge on the same variant for the same visitor.

Request URL: `POST https://api.oursprivacy.com/api/v1/experiments/assignments/{experiment_key}`

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `experiment_key` | path | string | Yes | The experiment's stable key. Surfaced in the dashboard under each experiment's setup tab. The experiment's stable key. Surfaced in the dashboard under each experiment's setup tab. |

### Request body (`application/json`, required)

Visitor + optional page context for eligibility. The schema describes canonical JSON inputs. The server also accepts values normalized by the preprocessing described on individual fields.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `token` | string | Yes | The experiment token (`exp_*`) for the experiment settings holding this experiment. Available from the dashboard. |
| `visitor_id` | string | Yes | Stable identifier for the visitor — typically the Ours visitor id from your browser cookie, or your own server-side user id if you keep the same id consistent across browser and server. |
| `context` | object \| null | No | Optional page context for URL + query-param eligibility. Variant bucketing is deterministic on `visitor_id` regardless of context. |
| `context.url` | string \| null | No | The current page URL. When provided, the experiment's URL patterns are evaluated for eligibility — visitors on non-matching URLs are returned `in_experiment: false`. Omit when the caller is pre-gating the request. |
| `context.search` | string \| null | No | The current query string (e.g. `?utm_source=meta`). When provided, the experiment's query-param conditions are evaluated for eligibility. If omitted, the query string is parsed from `url`. |
| `track_impression` | boolean \| null | No | When true (default), an `$experiment_impression` event is enqueued and the visitor's `experiment_assignments` map is updated. Set to false to read the assignment without recording an impression — useful for in-test diagnostics. |

### Responses

- `200`: The assignment outcome — including out-of-experiment results.
- `400`: Bad Request - Something about the body of your request is invalid. Please update your payload and try again.
- `401`: Unauthorized - you are not authorized to send events to Ours. Please contact support.
- `404`: The experiment key is unknown or not currently running.
- `500`: Internal Server Error.

Full schema: [OpenAPI specification](https://docs.oursprivacy.com/openapi.json).
