Skip to content

Zapier

Zapier’s Webhooks by Zapier app calls the API and hears when a job finishes. Zapier offers it on its paid plans. The overview explains the parts these settings use.

Zapier passes files between steps as links, so the job fetches the file from its link, and the work takes two Zaps:

  1. The second Zap, built first, starts when a job finishes: it gets the converted file and does something with it.
  2. The first Zap starts the job, with the second Zap’s address as the job’s webhook.

Nothing waits on a conversion, however long it takes.

  1. Start a Zap with Webhooks by Zapier and the Catch Hook trigger. Copy its URL (https://hooks.zapier.com/hooks/catch/…).
  2. Check it’s ours before you act on it: add Webhooks by Zapier’s GET action for https://api.formatjet.com/v1/jobs/ followed by the job’s ID from the hook (data.job.id), with the header Authorization: Bearer fj_live_…. Use its answer from here on, never the hook’s: a request that didn’t come from us can’t make the Zap act on a file or a status we didn’t give. It can still name one of your real jobs again if someone learns the hook’s URL, so keep that URL private, and have the Zap skip a job it has already handled and one whose metadata isn’t this Zap’s. (Checking the FormatJet-Signature header proves the request is ours. It needs the Catch Raw Hook trigger, which keeps the headers and the raw body, and a code step, as in Check the signature.)
  3. Add a Filter that goes on only when the answer’s status is completed and its mode is live: test jobs’ events say test, and anyone with a test key can send them anywhere.
  4. Add the step that uses the file, such as a storage app’s upload. For its file, map the answer’s output url: it works without a key until its expires_at.

To give the Catch Hook a sample, turn the first Zap on with a test key, as below, and run it once: test jobs cost nothing.

After your trigger (a new file in a folder, an email attachment), add Webhooks by Zapier’s POST action:

Setting Value
URL https://api.formatjet.com/v1/jobs
Payload Type Raw
Data The JSON below, with the file mapped from the trigger into url and the Catch Hook’s URL in webhook
Headers Authorization: Bearer fj_live_…. Content-Type: application/json. FormatJet-Client: zapier-webhooks
Data
{
"input": {
"url": "<the file, mapped from the trigger>"
},
"steps": [
{
"op": "convert",
"conversion": "word-to-pdf"
}
],
"metadata": {
"zap": "contracts"
},
"webhook": "<the Catch Hook URL of the second Zap>"
}

Use a slug from GET /v1/operations in place of word-to-pdf. metadata is yours: it comes back with the job, so the second Zap can tell your Zaps’ jobs apart. The answer is the job, with status awaiting_upload while we fetch the file.

We fetch the file from its link, up to your plan’s file size, so the link must open without signing in. If the job fails with import_failed, its error.detail says why: a link that answers 401 or 403 needs a shared or public link from the storage app instead.

Here is the same flow in curl, waiting for the job rather than hearing from it:

integrations-url.sh
#!/usr/bin/env bash
# Needs curl and jq.
set -euo pipefail
API=https://api.formatjet.com/v1
AUTH="Authorization: Bearer $FORMATJET_API_KEY"
# 1. A job from the file's address, as a platform that passes files as links makes it.
job=$(curl -sS --fail-with-body "$API/jobs" -H "$AUTH" -H "Content-Type: application/json" \
-H "FormatJet-Client: zapier-webhooks" \
-d '{"input": {"url": "https://formatjet.com/docs/samples/report.pdf"},
"steps": [{"op": "convert", "conversion": "pdf-to-markdown"}],
"metadata": {"workflow": "reports"}}')
id=$(jq -r .id <<< "$job")
# 2. Ask until it ends: each answer comes as soon as the job ends, or after 30 seconds.
status=$(jq -r .status <<< "$job")
until [[ $status == completed || $status == failed || $status == canceled ]]; do
job=$(curl -sS --fail-with-body "$API/jobs/$id?wait=30" -H "$AUTH")
status=$(jq -r .status <<< "$job")
done
[[ $status == completed ]] || { jq .error <<< "$job"; exit 1; }
# 3. Download the output with the key: the API redirects to the file's own URL, and curl
# leaves the key off when a redirect leads to another host.
curl -sS --fail-with-body -L "$API/jobs/$id/outputs/0" -H "$AUTH" -o report.md

The job’s webhook sends that job’s events. To send every job’s, or every job of some conversions, add the Catch Hook URL as a webhook endpoint instead, in the dashboard’s Webhooks page or with POST /v1/webhooks, narrowed with conversions (up to 50) or metadata. Then the first Zap leaves out webhook. The overview has the request.

An event can arrive twice, with the same id: acting once per job covers that too. Zapier answers each at once, which is what we need: we wait 10 seconds for an answer.