CrawlClick conversion postback API (cc_click)
Keep the cc_click value from the landing URL, and when the visitor converts, POST it from your server to /v1/conversions with your conversion key; CrawlClick answers accepted, pending or duplicate.
Status: Coming. The conversion postback lets an advertiser tell CrawlClick that a click from the CrawlClick Earn app led to a conversion on the advertiser’s own site, such as a signup or a purchase. It is a single server-to-server route on the control API. It applies only to clicks from the Earn app; campaigns on the publisher network need no code on your site.
How does the cc_click parameter reach my landing page?
When a person taps an offer in the Earn app, CrawlClick records the click and sends the person to your campaign’s landing URL with one query parameter added: cc_click, the click id. If the URL already has a query, &cc_click=… is appended; if it has a #fragment, the parameter goes before the fragment, which stays at the end. For a landing URL of https://shop.example/p?ref=ai#top, the person arrives at:
GET /p?ref=ai&cc_click=3f9a0c4e1b7d42a8966e05c3d1f8ab27#top HTTP/1.1
Host: shop.example
The click id is 32 hexadecimal characters. Your page must keep it: redirects that drop query parameters, or a consent banner that reloads the page without them, lose the click. Clicks that reach you without cc_click did not come from the Earn app, and you should not report them.
How do I store cc_click until the visitor converts?
Read cc_click on the first request, check that it is 32 hexadecimal characters, and keep it with the visitor: in your server-side session, or in a first-party, HttpOnly cookie. Keep the lifetime as long as your own attribution window. When the conversion happens, read it back and send the postback from your server. This Express example stores it in a cookie and reports it when an order is placed:
import express from 'express';
import cookieParser from 'cookie-parser';
const app = express();
app.use(cookieParser());
app.use(express.json());
const CLICK = /^[0-9a-fA-F]{32}$/;
// Keep cc_click from any landing request.
app.use((req, res, next) => {
const click = req.query.cc_click;
if (typeof click === 'string' && CLICK.test(click)) {
res.cookie('cc_click', click, {
httpOnly: true,
secure: true,
sameSite: 'lax',
maxAge: 30 * 24 * 60 * 60 * 1000,
});
}
next();
});
app.post('/orders', async (req, res) => {
// ... create the order ...
const click = req.cookies.cc_click;
if (typeof click === 'string' && CLICK.test(click)) {
const response = await fetch('https://api.crawlclick.com/v1/conversions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CRAWLCLICK_CONVERSION_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ click_id: click }),
});
console.log('crawlclick conversion', response.status, await response.text());
res.clearCookie('cc_click');
}
res.status(201).json({ ok: true });
});
app.listen(3000);
In production, send the postback from a job queue rather than inside the request, so a slow or failed call never delays your customer. The retry rules are below.
What does the conversions route accept and return?
POST/v1/conversionsComing
Report, from your own server, that a click from the CrawlClick Earn app converted.
- Host
- https://api.crawlclick.com
- Authentication
Authorization: Bearer cck_…, the conversion key created in the console. Creating a new key replaces the old one.- Source
- api-crawlclick-com/crates/crawlclick/src/earn_api.rs
Request body (JSON)
| Field | Type | Description |
|---|---|---|
| click_id | string | The value of the cc_click query parameter CrawlClick appended to your landing URL. |
Responses
202 · The conversion is recorded against a settled, paid click.
{"status": "accepted"}202 · The click has not settled yet, or is not yet known. CrawlClick retries it automatically for 30 days.
{"status": "pending"}202 · This click already converted. A conversion is paid once per click.
{"status": "duplicate"}Refusals
| Status | Code | Means | Do instead |
|---|---|---|---|
| 401 | invalid_key | The key is missing or is not the advertiser’s current conversion key. | Create a new key in the console (it is shown once) and store it server-side only. |
| 400 | bad_request | The body is not JSON with a click_id string. | Send {"click_id": "…"} with the cc_click value. |
| 404 | — | The body is {"status": "unknown_click"}, with no code. The click_id is not 32 hexadecimal characters, or the click was settled for another advertiser’s campaign. A well-formed id that has not settled yet is not refused: it is answered pending. | Send the cc_click value unchanged, in lower case as it arrived. Do not report conversions for traffic that did not arrive with one. |
| 404 | not_found | The CrawlClick Earn app is not enabled on this deployment. Every request gets this answer until it is. | Nothing to fix on your side. Keep the integration ready; the route starts answering when the Earn channel opens. |
| 503 | unavailable | The conversion could not be recorded, or accounts are unavailable. | Retry the same request. A conversion is recorded at most once per click, so a retry cannot double-count. |
| 500 | internal | An unexpected server error. | Retry later with the same body. |
The route reads the key before the body. A missing key, or one that does not start with cck_, gets 401 with code invalid_key and the sentence “a conversion key is required”; a well-formed key that is not your current one gets 401 invalid_key with “that conversion key is not valid”. A body that is not JSON with a string click_id gets 400 with code bad_request. The click id is trimmed of surrounding whitespace, and anything that is not 32 hexadecimal characters gets 404 {"status": "unknown_click"}. That 404 body has a status field, not error and code.
When is a conversion accepted, pending or duplicate?
All three answers are 202 Accepted, and all three mean you are done with that click.
{"status": "accepted"}: the click had already been settled and paid, it belongs to one of your campaigns, and the conversion is recorded as evidence.{"status": "pending"}: CrawlClick has not settled the click yet. The conversion is stored and retried automatically about once a minute for 30 days from when you reported it. If the click settles and was paid within that time, the conversion is recorded; otherwise it expires. You do not resend it.{"status": "duplicate"}: a conversion for this click id was already received. A conversion is counted once per click, so a retry, a double-submitted form or a second purchase from the same click changes nothing.
A click id CrawlClick has not settled is answered pending, not 404, because settlement can lag the click. A click that has settled for another advertiser’s campaign is answered 404 unknown_click. A conversion is paid, at the conversion price you set for the campaign in the console, only when its click was itself paid; a price of zero records the conversion as measurement and pays nothing.
How do I retry a failed postback safely?
The route is idempotent per click id: the first request for a click stores it, and every later request for that click returns duplicate. That makes retries safe.
- Retry on a network error, on
429(the control API’s per-address rate limit, see Conventions), on500with codeinternal, and on503. A503with codeunavailablecan mean the conversion was stored but not yet written as evidence; it is then retried with the pending conversions, and your retry seesduplicate. A503with an empty body andRetry-After: 1means the server was over capacity and stored nothing; your retry is processed normally. - Do not retry
400,401or404. Fix the body, the key or the click id instead. - Treat any
202as final, includingduplicate.
How do I send the postback with curl?
curl -sS https://api.crawlclick.com/v1/conversions \
-H "Authorization: Bearer $CRAWLCLICK_CONVERSION_KEY" \
-H "Content-Type: application/json" \
-d '{"click_id": "3f9a0c4e1b7d42a8966e05c3d1f8ab27"}'
How do I send the postback from Node.js?
This uses the fetch built into Node.js 18 and later, with the retry rules above.
const ENDPOINT = 'https://api.crawlclick.com/v1/conversions';
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
export async function reportConversion(clickId: string): Promise<string> {
for (let attempt = 0; attempt < 5; attempt++) {
try {
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CRAWLCLICK_CONVERSION_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ click_id: clickId }),
});
const body = await res.json().catch(() => ({}));
if (res.status === 202) return body.status; // accepted | pending | duplicate
if (![429, 500, 503].includes(res.status)) {
throw new Error(`conversion refused: ${res.status} ${JSON.stringify(body)}`);
}
} catch (error) {
if (error instanceof Error && error.message.startsWith('conversion refused')) throw error;
}
await sleep(1000 * 2 ** attempt + Math.random() * 250);
}
throw new Error('conversion not delivered after 5 attempts');
}
console.log(await reportConversion(process.argv[2]));
How do I send the postback from Python?
This uses only the standard library.
import json
import os
import random
import sys
import time
import urllib.error
import urllib.request
ENDPOINT = "https://api.crawlclick.com/v1/conversions"
def report_conversion(click_id: str) -> str:
body = json.dumps({"click_id": click_id}).encode()
for attempt in range(5):
request = urllib.request.Request(
ENDPOINT,
data=body,
method="POST",
headers={
"Authorization": "Bearer " + os.environ["CRAWLCLICK_CONVERSION_KEY"],
"Content-Type": "application/json",
},
)
try:
with urllib.request.urlopen(request, timeout=10) as response:
return json.load(response)["status"] # accepted | pending | duplicate
except urllib.error.HTTPError as error:
if error.code not in (429, 500, 503):
detail = error.read().decode()
raise RuntimeError("conversion refused: %d %s" % (error.code, detail))
except urllib.error.URLError:
pass
time.sleep(2**attempt + random.random() / 4)
raise RuntimeError("conversion not delivered after 5 attempts")
if __name__ == "__main__":
print(report_conversion(sys.argv[1]))
How do I send the postback from Go?
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"os"
"time"
)
const endpoint = "https://api.crawlclick.com/v1/conversions"
func reportConversion(clickID string) (string, error) {
payload, _ := json.Marshal(map[string]string{"click_id": clickID})
client := &http.Client{Timeout: 10 * time.Second}
for attempt := 0; attempt < 5; attempt++ {
req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewReader(payload))
if err != nil {
return "", err
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("CRAWLCLICK_CONVERSION_KEY"))
req.Header.Set("Content-Type", "application/json")
res, err := client.Do(req)
if err == nil {
body, _ := io.ReadAll(res.Body)
res.Body.Close()
if res.StatusCode == http.StatusAccepted {
var out struct {
Status string `json:"status"`
}
if err := json.Unmarshal(body, &out); err != nil {
return "", err
}
return out.Status, nil // accepted | pending | duplicate
}
switch res.StatusCode {
case http.StatusTooManyRequests, http.StatusInternalServerError, http.StatusServiceUnavailable:
default:
return "", fmt.Errorf("conversion refused: %d %s", res.StatusCode, body)
}
}
time.Sleep(time.Duration(1<<attempt)*time.Second + time.Duration(rand.Intn(250))*time.Millisecond)
}
return "", fmt.Errorf("conversion not delivered after 5 attempts")
}
func main() {
status, err := reportConversion(os.Args[1])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Println(status)
}
How do I send the postback from PHP?
This uses the cURL extension that ships with most PHP builds.
<?php
function report_conversion(string $clickId): string
{
$payload = json_encode(['click_id' => $clickId]);
for ($attempt = 0; $attempt < 5; $attempt++) {
$ch = curl_init('https://api.crawlclick.com/v1/conversions');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('CRAWLCLICK_CONVERSION_KEY'),
'Content-Type: application/json',
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($status === 202) {
return json_decode($body, true)['status']; // accepted | pending | duplicate
}
if ($body !== false && !in_array($status, [429, 500, 503], true)) {
throw new RuntimeException("conversion refused: $status $body");
}
usleep((2 ** $attempt) * 1000000 + random_int(0, 250000));
}
throw new RuntimeException('conversion not delivered after 5 attempts');
}
echo report_conversion($argv[1]), PHP_EOL;
How do I get or replace a conversion key?
Create the key in the console at console.crawlclick.com, on the advertiser account that owns the campaigns. The key starts with cck_ and is shown once, so copy it straight into your server’s secret store as CRAWLCLICK_CONVERSION_KEY. An account has one conversion key at a time: creating a new one replaces the old one immediately, and the old key starts getting 401 invalid_key. To rotate without losing conversions, deploy the new key as soon as you create it; postbacks that fail with 401 during the switch can be retried with the new key, because the click id is what identifies the conversion. In the console you also set each campaign’s conversion price, or zero to measure without paying; figures are on www.crawlclick.com/pricing/.
Related pages: Endpoints, Errors, Conventions, Earn MCP connector.