Idempotency
Every endpoint accepts an optional Idempotency-Key header. Use it to safely retry requests when your network or our backend has a hiccup.
How it works
-
Your first request runs normally. We store the response body keyed on
(apiKeyId, idempotencyKey). -
Any request with the same key within 24h returns the same response with a header:
X-Idempotent-Replay: true -
Two days later the cached row is purged. Calling with the same key again will re-execute the request.
Guidelines
- The key is string ≤ 128 characters.
- Generate one per business action:
order_<order_id>,signup_<user_id>_<timestamp>, etc. - Don’t reuse keys across different operations. Each key represents one logical “attempt”.
- The Idempotency-Key is scoped per API key — two different keys may use the same string without conflict.
Example
Fire a Purchase event with retry safety:
curl -X POST https://adtarget.io/api/v1/events/conversion \
-H "Authorization: Bearer atk_live_..." \
-H "Idempotency-Key: order_98765" \
-H "Content-Type: application/json" \
-d '{ "telegramUserId": 1234567890, "channelId": "-1001234567890", "eventType": "Purchase", "value": 49.00, "currency": "USD" }'If your network drops the response and you retry with the same Idempotency-Key, AdTarget returns the original conversionId without firing a second Meta event.
We don’t validate that the body matches the original request. If you reuse a key with a different body, you’ll get back the original response — not the new one. Always generate a fresh key for a different intent.
What gets cached
- The full response body and HTTP status code.
- The
conversionIdfor forensic linking.
We do not cache anything about the request body itself. The key is the sole replay identifier.
Combined with Meta dedup
AdTarget has two layers of duplicate protection:
Idempotency-Keyreplays the same API response for the same logical request within 24h.- Conversion upsert logic reuses recent matching events for the same resolved site, Telegram user, channel, and event type. Pending/failed/skipped events are updated and retried; sent events are returned with
deduplicated: trueand are not sent again.
Meta CAPI also deduplicates within 48h based on event_id.
Déduplication optionnelle des visites pour /track/init
POST /backend/track/init accepte un UUID visitRequestId optionnel dans le corps JSON. C’est le champ public recommandé ; l’ancien nom gatewayRequestId reste accepté comme alias rétrocompatible. Si les deux champs sont envoyés, ils doivent contenir le même UUID ; des valeurs différentes renvoient HTTP 400. Réutilisez le même UUID pour réessayer une même page vue : AdTarget renvoie la même visite et complète uniquement les données d’attribution encore manquantes. Les valeurs existantes et le routage ne sont jamais écrasés. Les tentatives doivent conserver les mêmes websiteId, tempId et sessionId ; tout changement d’identité navigateur est refusé.
Sans visitRequestId, le comportement historique reste inchangé : chaque appel crée une visite distincte, même dans la même session navigateur. Utilisez un nouvel UUID pour chaque nouvelle page vue réelle.
Nouvelles tentatives direct-invite sans clé API
POST /backend/track/direct-invite utilise le champ visitRequestId (UUID) du corps, et non l’en-tête Idempotency-Key. L’alias historique gatewayRequestId reste accepté. Réutilisez le même UUID pour les tentatives d’une même redirection.
Les appels répétés créent une seule visite, une seule entrée PageView et une seule invitation Telegram. Ils complètent uniquement les champs encore absents sans écraser une valeur existante. websiteId, tempId et sessionId doivent identifier la visite d’origine. Utilisez un nouvel UUID pour un nouveau clic.