For the complete documentation index, see llms.txt. This page is also available as Markdown.

Code examples

The examples below call POST /v1/email and its batch form from a shell with curl, from Python and from Node.js. Every operation of this document also publishes its own samples in x-codeSamples — curl, Python, Node.js and the raw HTTP request — and the request bodies are the examples shown on each operation. Each example sends dlp_live_your_key_here where the API key goes. The curl examples run in a POSIX shell and generate each Idempotency-Key with uuidgen, which ships with macOS and many Linux distributions (Debian-based systems carry it in uuid-runtime); any unique string up to 255 printable ASCII characters is a valid key. The Python examples need the requests package (pip install requests), and the Node.js examples are CommonJS (save them as .js or .cjs) and use the built-in fetch of Node.js 18 or later.

Submit and poll

Every example calls https://api.delpha.io. POST /v1/email sends the request example published on the operation — email, first_name, last_name and website — and answers 202 with a job_id in the body and the Location and Retry-After headers. The loop then sends GET /v1/email/{job_id}, the request the poll operation's own sample describes, each time Retry-After seconds have passed, and branches on the HTTP status, reading code on a 504 only:

  • 200 ends the loop with the result.

  • 202 (the job is still running), 429 and 503 are waited out for the Retry-After the response carries, and the poll is sent again.

  • 504 is waited out the same way unless its code is job_timeout, which the Error catalog defines as a job that will never complete; that ends the loop.

  • Any other status ends the loop — 404 (no job for this id), 409 (the credit reservation expired before delivery) and 500 among them — and the last body is printed.

# The same key with the same body replays the first 202, with no second charge.
IDEMPOTENCY_KEY=$(uuidgen)

RESPONSE=$(curl -sS -i -X POST "https://api.delpha.io/v1/email" \
  -H "Authorization: Bearer dlp_live_your_key_here" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  --data '{"email":"jordan.rivera@example.com","first_name":"Jordan","last_name":"Rivera","website":"https://delpha.io/"}')
# The API's status line is the last one: behind a proxy, curl -i prints the
# proxy's `200 Connection established` first.
STATUS=$(printf '%s\n' "$RESPONSE" | sed -n 's/^HTTP[^ ]* \([0-9]*\).*/\1/p' | tail -n 1)
echo "$STATUS"

if [ "$STATUS" = 202 ]; then
  JOB_ID=$(printf '%s\n' "$RESPONSE" | sed -n 's/.*"job_id": *"\([^"]*\)".*/\1/p')
  while :; do
    RETRY_AFTER=$(printf '%s\n' "$RESPONSE" | tr -d '\r' | sed -n 's/^[Rr]etry-[Aa]fter: *//p' | tail -n 1)
    sleep "${RETRY_AFTER:-1}"
    RESPONSE=$(curl -sS -i "https://api.delpha.io/v1/email/$JOB_ID" \
      -H "Authorization: Bearer dlp_live_your_key_here")
    STATUS=$(printf '%s\n' "$RESPONSE" | sed -n 's/^HTTP[^ ]* \([0-9]*\).*/\1/p' | tail -n 1)
    case "$STATUS" in
      202 | 429 | 503) ;;
      504) printf '%s\n' "$RESPONSE" | grep -q '"code": *"job_timeout"' && break ;;
      *) break ;;
    esac
  done
  echo "$STATUS"
fi

# The body is the last line of the output.
printf '%s\n' "$RESPONSE" | tail -n 1

Idempotent submit

The same POST /v1/email, sent twice with one Idempotency-Key and the same body. Both answers are 202 with the same job_id; the second carries Idempotent-Replayed: true, starts no new job and adds no charge. A key is honoured for 24 hours and is scoped to the team; the same key with a different body answers 409 idempotency_key_reuse (see Idempotency).

Batch

POST /v1/email/batch sends the batch request example — an items list of 1 record — as one job, and the same loop polls GET /v1/email/batch/{job_id}. Its 200 carries counts (the per-item totals), result_url (a presigned link to the result file) and, when that file is 1 MB or smaller, the results inline as result_data. Only the items that succeed are charged (see Batch operations).

Calling in test mode

The submit and one poll, sent with a key created in test mode at Developer → API keys in place of the placeholder; nothing in a credential tells its mode. Every response the API renders to a test-mode call carries X-Delpha-Mode: sandbox, and a live response carries no such header, so the example prints that header from both answers. As the Test mode section states, a test-mode job is complete the moment it is accepted: the first poll answers 200 with the result rather than the transient 202, the result comes from the published table of canned results, and no credit is reserved.

Errors and webhooks

Every code an error body can carry is defined in the code enum of the Error schema: its meaning, the status it usually rides on, and whether a later attempt can succeed (see Errors). The gateway's own 401, 403 and shared-floor 429 carry a GatewayError body with no code, which is why the loops above branch on the status.

A subscriber to the job lifecycle events is notified when a job finishes instead of polling for it, then fetches the result with one GET on the poll URL — events never carry the result. The Python and Node.js snippets that check the Delpha-Signature of each delivery are in the Webhooks section, under Verifying a delivery, and on the Webhooks page.

Last updated

Was this helpful?