Participate Endpoint
The participate endpoint checks for active tests in the Splitty Test system for the given section and returns a selected variation.
Endpoint Details
Path: /split-test/participate
Method: POST
Payload:
- section_id: [string] - The ID of the section to return a test for.
- data: [object] - A plain object with details about the user. This will be added to the user session and is used when determining audience filters and user segments.
- test_id: [string] - (Optional) The ID of a test to force upon the user.
- variation_id: [string] - (Optional) The ID of a variation to force upon a user. This is useful when displaying a preview of the test variation.
- ignore: [boolean] - (Optional) When forcing a test or variation, the system will ignore session logging and updates. Set this to
falseto log or update the session.
Return Values
| Status | Data Type | Reason |
|---|---|---|
| 204 | (Empty) | There are no active tests for the given section |
| 200 | {
test_id: null;
variation: null;
session_id: string;
} | Selecting a test was skipped or no test was selected for the given section |
| 200 | {
test_id: null;
variation: {
id: string;
data: Record<string, any>;
};
session_id: string;
} | A variation was forced and returned for the given section |
| 200 | {
test_id: string;
variation: {
id: string;
data: Record<string, any>;
};
session_id: string;
} | A test and variation were selected and returned for the given section |
| 400 | {
statusCode: number;
error: string;
reason?: string;
} | There was a problem with the payload you sent to the endpoint |
| 500 | {
statusCode: number;
error: string;
reason?: string;
} | There was a problem on the server or an unknown error occured |
Example Request
js
// We will use fetch for the example
// Make the request to the participate endpoint
const response = await fetch('https://mysplittytest.com/split-test/participate', {
method: 'POST',
headers: {
'Authorization': 'API-Key YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
section_id: 'cta_button',
data: {
day_part: 'weekday'
}
});
});
// Parse the response
if (response.ok) {
throw new Error('Unable to get test data!');
}
const { variation } = await response.json();
// Apply the variation data where needed...
const cta_button = document.getElementById('cta-button');
if (cta_button && variation.data.label) {
cta_button.textContent = variation.data.label;
}