Example: a campaign via API
This walkthrough sets up an exit-intent survey on the checkout, entirely through the API: a data field for the cart value, an audience, the campaign itself, and finally its results. You need a token with the scopes datafields:write, audiences:write, campaigns:write and insights:read.
export CL_TOKEN=cl_sk_...
export PROJECT=prj_4k9x2m7q1v8b3n6c5z0wd # from GET /v1/projects
1. Create a data field
The survey should only show for carts of 50 or more. For that, the script needs the cart value:
curl -X POST https://api.conversionloop.net/v1/projects/$PROJECT/data-fields \
-H "Authorization: Bearer $CL_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "key": "cart_value", "label": "Cart value", "type": "number" }'
On your checkout, pass the value to the script on every page load:
<script>
window.conversionloop = window.conversionloop || { q: [] };
window.conversionloop.q.push(['set', { cart_value: 149.90 }]);
</script>
2. Create an audience
Visitors on the checkout who are about to leave and have at least 50 in their cart:
curl -X POST https://api.conversionloop.net/v1/projects/$PROJECT/audiences \
-H "Authorization: Bearer $CL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Leaving the checkout",
"rules": { "groups": [ { "id": "g1", "match": "all", "conditions": [
{ "id": "c1", "type": "url", "operator": "contains", "value": "/checkout" },
{ "id": "c2", "type": "exit_intent", "operator": "is_true" },
{ "id": "c3", "type": "data_field", "field": "cart_value", "operator": "gte", "value": 50 }
] } ] }
}'
The response contains the audience id (aud_…). All condition types are listed under Audience rules.
3. Create the campaign
curl -X POST https://api.conversionloop.net/v1/projects/$PROJECT/campaigns \
-H "Authorization: Bearer $CL_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Why are you leaving the checkout?",
"slug": "checkout-exit",
"audienceId": "aud_2m8k4x9q1v7b3n6c5z0wd",
"content": {
"kind": "single_choice",
"question": "What is stopping you from ordering today?",
"options": [
{ "id": "price", "label": "The price" },
{ "id": "shipping", "label": "Shipping costs or time" },
{ "id": "unsure", "label": "Not sure the product fits" },
{ "id": "other", "label": "Something else", "followUp": "What is it?" }
]
},
"appearance": { "position": "center_modal", "backdrop": true },
"delivery": { "frequency": { "maxImpressions": 1, "windowDays": 30 } }
}'
The campaign is created as a draft. Nobody sees it yet. Option ids are what you get back in the results, so choose stable, readable ones.
4. Go live
curl -X POST https://api.conversionloop.net/v1/projects/$PROJECT/campaigns/cmp_9x2k4m7q1v8b3n6c5z0wd/status \
-H "Authorization: Bearer $CL_TOKEN" \
-H "Content-Type: application/json" \
-d '{ "status": "live" }'
If something is missing, the API answers 422 and says what:
{
"error": {
"code": "unprocessable",
"message": "This campaign cannot go live yet.",
"details": ["An audience must be assigned."]
}
}
The campaign reaches visitors within about five minutes. To check it on your site straight away, open the browser console and run conversionloop.trigger('checkout-exit').
To pause it later, set the status to paused; to resume, set it to live again.
5. Read the results
Answers per option, ratings, free-text answers and a daily timeline:
curl "https://api.conversionloop.net/v1/projects/$PROJECT/campaigns/cmp_9x2k4m7q1v8b3n6c5z0wd/insights?from=2026-11-01T00:00:00Z" \
-H "Authorization: Bearer $CL_TOKEN"
All answers as CSV, including the cart value of each:
curl https://api.conversionloop.net/v1/projects/$PROJECT/campaigns/cmp_9x2k4m7q1v8b3n6c5z0wd/responses.csv \
-H "Authorization: Bearer $CL_TOKEN" \
-o checkout-exit.csv
A weekly report in Node.js
Response rates of all campaigns over the last seven days, for example for a Slack message or a team dashboard. Runs on Node.js 18 or later, without dependencies:
const API = 'https://api.conversionloop.net';
const headers = { Authorization: `Bearer ${process.env.CL_TOKEN}` };
async function get(path) {
const response = await fetch(API + path, { headers });
if (!response.ok) {
const { error } = await response.json();
throw new Error(`${response.status} ${error.code}: ${error.message}`);
}
return response.json();
}
const from = new Date(Date.now() - 7 * 86_400_000).toISOString();
const { data: projects } = await get('/v1/projects');
for (const project of projects) {
const { data } = await get(`/v1/projects/${project.id}/insights?from=${from}`);
for (const row of data.filter((entry) => entry.campaign.status === 'live')) {
const rate = row.responseRate === null ? '–' : `${(row.responseRate * 100).toFixed(1)} %`;
console.log(`${project.name} · ${row.campaign.name}: ${row.responses} answers, ${rate}`);
}
}