Skip to content

Calling a webhook

This page is for whoever writes or configures the system that sends the requests. Send it to your developer, or to the support team of your shop or CRM. It covers what a webhook accepts, what it answers and how to send a request safely.

Each webhook has its own address, shown on its settings page:

https://api.doxtly.com/v1/webhooks/3f2a9c1e-7b44-4d21-9a53-0c6e8f1d2b70

A typical call with a token:

Terminal window
curl -X POST 'https://api.doxtly.com/v1/webhooks/3f2a9c1e-7b44-4d21-9a53-0c6e8f1d2b70' \
-H 'Authorization: Bearer <token>' \
-H 'Content-Type: application/json' \
-d '{"orderId": "A-17", "email": "lena.fischer@hartwell.example"}'

The Example call on the webhook’s page gives you this command with its real settings, apart from a signature, which you add yourself.

The Example call section of a webhook's page, open, with a curl command and a copy button
Webhook’s authentication Send
Token, header Authorization: Bearer <token>
Token, address parameter ?token=<token> in the address
Access key X-Api-Key: <API key> and X-Api-Secret: <API secret>
None Nothing

Credentials and signatures are never kept with the request and never reach a workflow. That covers the Authorization, Proxy-Authorization, Cookie, X-Api-Key and X-Api-Secret headers, the signature header and, on a webhook that takes its token there, the token parameter.

Content-Type How the body is read
application/json, or any type ending in +json JSON
None JSON
application/x-www-form-urlencoded Form fields
Any text/... type Text, as it is
Anything else, multipart/form-data included Refused with 415

So a webhook doesn’t accept file uploads. Send a link to the file instead. The type only counts when there is a body: an empty one passes whatever the header says.

A POST, PUT or PATCH carries its data in the body, a GET in the address parameters, and a DELETE wherever the webhook is set to read it from. A body sent along with address data isn’t read as data, but its type is still checked. An empty body is allowed: the workflow then starts without data, unless the webhook’s JSON Schema requires some.

Form fields and address parameters always arrive as text. If the webhook has a JSON Schema, a field sent as quantity=2 is the string "2", not a number.

If the webhook has Check the signature on, sign the request with the shared secret.

The Standard Webhooks libraries do this for you. By hand:

signed = webhook-id + "." + webhook-timestamp + "." + body
key = base64_decode(secret without "whsec_")
signature = "v1," + base64(HMAC_SHA256(key, signed))

Send three headers:

Header Value
webhook-id A unique identifier of the message. Keep it the same when you send the message again.
webhook-timestamp The current time in Unix seconds, at most 5 minutes off.
webhook-signature One or more signatures, separated by spaces. Sending two lets you change the secret without a gap.
signature = prefix + hex|base64(HMAC_SHA256(secret, body))

Compute it over the raw body exactly as sent, and put it in the header the webhook names. Hex may be upper or lower case.

Every response carries an X-Request-ID header. It’s the identifier the Requests tab shows and searches by, so log it on your side and quote it when you ask about a call. If you send your own X-Request-ID and it’s a valid UUID, Doxtly uses and returns yours.

The Request identifier (X-Request-ID) field on a request's page, with a copy button

An accepted request gets the status set on the webhook, by default 202, with no body or the webhook’s fixed body, sent as application/json or text/plain. The status means Doxtly took the request. The workflows start with it and finish in their own time, and there is no way to get their result in this response. If you need a result back, have the workflow call your system with its Webhook step.

The checks run in the order below, and the first one that fails answers.

Order Check Status code
1 The organization’s rate limits 429, with Retry-After Not recorded in the log
2 The webhook is on 404 inactive
3 The method 405, with an Allow header method_not_allowed
4 The credentials 401, with WWW-Authenticate: Bearer for a token in the header unauthorized
5 The body’s size 413 payload_too_large
6 The signature 401 signature_invalid
7 The content type 415 unsupported_media_type
8 The body is what its type says 400 malformed
9 The idempotency key is present and well formed 400 idempotency_key_missing, malformed
10 The JSON Schema 422 invalid_data
11 The idempotency key isn’t reused or in use 422, 409 idempotency_key_reused, idempotency_key_in_use
12 The plan can run the workflows 503, with Retry-After: 3600 limit_exceeded

Two more answers can come at any point. An address of no webhook answers 404 and is recorded nowhere. If Doxtly itself can’t start the workflows, the answer is 503 with Retry-After: 30 and the code failed.

Refusals come as a JSON problem document. code is the field to read in a program, while title, detail and the messages of violations are written for people, in the language Accept-Language asks for, if it is Polish, English, Spanish, German, Portuguese, French, Ukrainian, Thai, Chinese, Hindi, Arabic, Japanese, Turkish or Italian, and in English otherwise. A message the schema’s author wrote in $error is told as written.

{
"type": "https://tools.ietf.org/html/rfc4918#section-11.2",
"title": "Unprocessable Content",
"status": 422,
"detail": "The data does not match the schema of this webhook.",
"instance": "/v1/webhooks/3f2a9c1e-7b44-4d21-9a53-0c6e8f1d2b70",
"code": "invalid_data",
"violations": [
{ "field": "/orderId", "message": "The value must be of type string, not integer." }
]
}

violations appears when the refusal has specific problems to report: at most ten for a schema, one for a body that doesn’t parse or an idempotency key that isn’t valid.

Answer What to do
2xx Nothing.
409 Send it again after a second. The first request with this key is still being handled.
429 Wait as long as Retry-After says, then send it again.
503 Wait as long as Retry-After says, then send it again. With limit_exceeded, it goes through once the plan has room. With failed, it should go through on the next try.
Any other 4xx Don’t repeat it unchanged. Something has to be corrected first.

Networks fail. If you sent a request and got a timeout, you can’t know whether Doxtly received it. An idempotency key makes it safe to send it again.

Put a unique value for the event in the Idempotency-Key header: up to 255 printable characters. An order number plus the event’s name works well, for example A-17-paid. On a webhook checking Standard Webhooks signatures, webhook-id is used when there is no Idempotency-Key.

What happens to a second request with the same key, to the same webhook, within a day of the first:

Situation Answer Workflows
The first was answered The same status as the first, with the header Idempotent-Replayed: true Nothing starts
The first is still being handled 409, with Retry-After: 1 Nothing starts
The same key with different content 422 Nothing starts
The first failed, or was cut off for more than two minutes Handled normally Only the workflows the first didn’t start

“Same content” means the same method, address parameters and body. After a day the key is forgotten, and a request with it counts as new.

A repeat passes the same checks as any request first, up to the webhook’s schema. The plan’s workflow runs are not among them: a repeat starts nothing, so an answered key replays, and a key in use or reused answers 409 or 422, even once your plan has run out of runs. Only a request that would start workflows answers 503 limit_exceeded, and it holds no key: send it again once there are runs. The same goes for any other refusal, so a request you corrected and sent again with the same key is handled as new.