Working with the API
Idempotency
Retry a send safely, without sending it twice.
A send can time out after Ghala took it. Retrying blindly could message the person twice. Send an Idempotency-Key header, a fresh value per send, and retry with the same value:
curl https://v3.ghala.io/v1/messages \
-H "Authorization: Bearer $GHALA_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order-1042-confirmation" \
-d '{"channel": "sms", "from": "ACME", "to": ["255700000001"], "type": "text", "text": "Your order 1042 is confirmed"}'A value tied to what you are sending for, such as the order it confirms, makes a retry use the same key without you storing one.
What comes back
- The same key with the same request answers the first answer again, with the header
Idempotency-Replayed: true. Nothing is sent or charged twice. - The same key with a different request is
409 idempotency_key_reused. - The first request still running is
409 idempotency_in_progress. Retry shortly. - A test key's key on a live request is
409 idempotency_key_reused, never replayed.
Rules
- Sending a message, a one-time code, and launching, resuming or retrying a campaign take a key.
- A key is 1 to 255 visible ASCII characters, belongs to your workspace, and is kept 24 hours.
- A
5xxthat certainly sent nothing frees its key: retry with the same value. - Any other failure, a provider timeout included, is kept and replayed, because the message may have gone out. Look the message up before you send again with a new key.