Skip to main content

Deliver an export to a webhook

An export ends with a file to download, and a pipeline would have to keep asking whether it is ready. Webhook delivery pushes the result instead. Apiome sends one signed POST to your URL with the export's file manifest, its fidelity report and the bundle itself. If your endpoint is down, Apiome tries again.

Delivery works on an export job that has finished (see How an export runs). To compare the channels, see Deliver an export.

Before you start​

  • A public HTTPS endpoint. Apiome refuses URLs that point into private, loopback or link-local networks, such as localhost, 10.0.0.0/8 or the cloud metadata address. It checks when you send the request and again on every attempt.
  • A shared secret of 16 to 512 characters that your endpoint also knows. Apiome signs the body with it once and never stores it.
  • The versions:publish permission. Sending an export outside the workspace needs the same permission as a git delivery.
  • A completed export. A dry run has no bundle to deliver, and an export whose download has expired has to be run again.

Deliver an export​

Send the job's id, your URL and the secret:

curl -X POST "$APIOME/v1/export/acme/jobs/$JOB_ID/deliveries/webhook" \
-H "Authorization: Bearer $APIOME_API_KEY" -H "Content-Type: application/json" \
-d '{"url": "https://ci.example.com/hooks/apiome", "secret": "'"$WEBHOOK_SECRET"'"}'
FieldWhat it does
urlThe endpoint to send the result to.
secretThe shared secret the body is signed with.
artifactauto (the default) puts the bundle inside the body when it is 1 MiB or less, and sends a fetch link otherwise. fetch always sends a fetch link.

Apiome makes the first attempt before it answers. The answer is the delivery run: its status, the receiver's status code and every attempt so far. Every field is in the export delivery reference. The URL is always shown without its query string, because webhook URLs often carry a token there.

What your endpoint receives​

A JSON body with "schemaVersion": "export.webhook-delivery.v1" and "event": "export.delivered":

KeyWhat it holds
deliveryIdThe delivery's id, the same on every retry.
createdAtWhen the delivery was requested.
exportThe artifact, version, target (or multi with every targets entry) and snapshot hash.
manifest.filesEvery file in the bundle, with its path, size and media type.
fidelityThe summary (tier, preserved share, counts), the full report, and a reportUrl that opens it in Export studio.
artifactThe bundle: filename, mediaType, sizeBytes, sha256, and either the content or a fetch link.
job.downloadPathThe job's own download path, for callers that have Apiome credentials.

Inline bundles (artifact.delivery: inline) carry content. A single file is UTF-8 text (encoding: utf-8), and a multi-file bundle is its zip in base64 (encoding: base64).

Large bundles (artifact.delivery: fetch) carry a url and an expiresAt instead. The link needs no Apiome sign-in, because its signature is the credential. It works for 24 hours or until the export's download expires, whichever comes first. Check the file you download against sha256.

Verify the signature​

Every request carries these headers:

HeaderValue
X-Apiome-Signaturesha256= plus the hex HMAC-SHA256 of the raw body, keyed with your secret.
X-Apiome-Eventexport.delivered
X-Apiome-DeliveryThe delivery's id. A retry sends the same id, so you can drop duplicates.
X-Apiome-Delivery-Attempt1 for the first attempt, then 2, 3 and 4.

Compute the HMAC over the bytes exactly as they arrived, before parsing the JSON, and compare it in constant time:

import hashlib
import hmac

def is_from_apiome(body: bytes, header: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(secret.encode(), body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, header)

This is the same scheme as Apiome's other outgoing webhooks, so one verifier serves both.

Retries​

Answer with any 2xx status to accept the delivery. Otherwise, the answer decides what happens next:

Your endpoint answersWhat Apiome does
2xxThe run is delivered.
Nothing (refused connection, timeout), 408, 425, 429 or 5xxThe run is retrying. Apiome tries again after 10 seconds, 1 minute and 5 minutes, waiting longer when a 429 or 503 sends Retry-After. After four attempts, the run is failed.
3xxThe run is failed. Redirects are not followed, so send the final URL.
Any other 4xxThe run is failed. Your endpoint refused the delivery, so it is not retried.

Every retry sends the same body with the same signature.

When a delivery fails​

A failed run keeps every attempt, with your endpoint's status code and the start of its response, plus a stable errorCode:

errorCodeWhat to do
export-webhook-delivery-rejectedYour endpoint answered 3xx or 4xx. Check its URL, and that it accepts the signature.
export-webhook-delivery-attempts-exhaustedFour attempts got no answer or a 5xx. Fix the endpoint, then deliver again.
export-webhook-delivery-destination-refusedThe URL resolved to a private address on an attempt. Use a public endpoint.

Some problems are refused before anything is sent:

  • An invalid URL or secret answers 400 with export-webhook-delivery-request-invalid.
  • A URL that resolves to a private address answers 400 with export-webhook-delivery-destination-refused.
  • An unfinished job answers 409, and an expired download 410. Run the export again, then deliver it.

A bundle that needs a fetch link answers 409 with export-webhook-delivery-fetch-url-unavailable when the server has no public address configured. An administrator sets APIOME_API_PUBLIC_URL, or raises APIOME_EXPORT_WEBHOOK_INLINE_MAX_BYTES so the bundle fits in the body.

See past deliveries​

GET /v1/export/{tenant}/jobs/{job_id}/deliveries/webhook lists a job's deliveries, newest first, with every attempt. Every delivery is also written to the audit log as export.webhook_delivery, with your endpoint's host but not its full URL.