n8n
n8n’s HTTP Request node calls the API, and its Webhook node hears when a job finishes. The overview explains the parts these settings use.
Your key
Section titled “Your key”In the HTTP Request node, set Authentication to Generic Credential Type, then Bearer Auth, and make a credential whose token is your API key. Header Auth works too, with the name Authorization and the value Bearer fj_live_…. n8n keeps the key in its credentials, out of the workflow.
Convert a file
Section titled “Convert a file”Put an HTTP Request node after the node that has the file, such as Read/Write Files from Disk or a download from your storage, and set:
| Setting | Value |
|---|---|
| Method | POST |
| URL | https://api.formatjet.com/v1/convert |
| Authentication | The credential above |
| Send Query Parameters | conversion: a slug from GET /v1/operations, such as word-to-pdf (or to: the format to make). response: file |
| Send Headers | FormatJet-Client: n8n-http |
| Send Body | Form-Data, one parameter of type n8n Binary File: name file, Input Data Field Name the binary field that holds the file (often data) |
| Options → Response | Response Format: File, put in the field data |
The node’s output is the converted file, named for the conversion (report.docx comes back as report.pdf), ready for the next node. response=file matters here: n8n asks for JSON first by default, which would get you the job instead of the file.
The same request in curl:
curl -sS --fail-with-body "https://api.formatjet.com/v1/convert?conversion=pdf-to-markdown&response=file" \ -H "Authorization: Bearer $FORMATJET_API_KEY" \ -H "FormatJet-Client: n8n-http" \ -F file=@report.pdf \ -o report.mdConversions that take longer
Section titled “Conversions that take longer”If a conversion hasn’t finished within 30 seconds, the API answers 202 with the job, which carries on. For files that may take longer (scans read with OCR, long recordings), ask for the job instead and wait for it:
- In the node above, set
responsetojoband Response Format to JSON. - Add an If node:
{{ $json.status }}iscompleted. - On false, an HTTP Request node with the method
GETasks forhttps://api.formatjet.com/v1/jobs/{{ $json.id }}with the query parameterwaitset to a number of seconds up to 30, then goes back to the If node. Each answer comes as soon as the job ends, so no Wait node is needed. Stop the loop whenstatusisfailedorcanceledtoo. - On true, an HTTP Request node downloads the file: Authentication None, URL
{{ $json.outputs[0].url }}, Response Format File. That URL needs no key. Or keep the credential and usehttps://api.formatjet.com/v1/jobs/{{ $json.id }}/outputs/0, which redirects to it.
Start a workflow when a job finishes
Section titled “Start a workflow when a job finishes”- Add a Webhook node: HTTP Method
POST, Respond Immediately, and under Options turn on Raw Body if you’ll check signatures. Copy its Production URL. - Add the URL as a webhook endpoint: in the dashboard’s Webhooks page, or with the request below. Narrow it with
conversionsormetadataso it hears only the jobs this workflow cares about; the answer’ssecretis the endpoint’s signing secret. - Publish the workflow, so the production URL listens.
curl https://api.formatjet.com/v1/webhooks \ -H "Authorization: Bearer $FORMATJET_API_KEY" \ -H "Content-Type: application/json" \ -d '{"url": "https://hooks.example.com/formatjet/reports", "events": ["job.completed", "job.failed"], "conversions": ["pdf-to-markdown"], "metadata": {"workflow": "reports"}}'The node’s output has the event in body: the job is body.data.job, with its status, outputs and metadata. Self-hosted n8n needs a public HTTPS address for its webhooks: we don’t send events over plain HTTP or to private addresses.
Check it’s ours before you act on it. The signature proves it: a Code node can follow Check the signature with Node’s crypto module, over the raw body (self-hosted n8n allows crypto in Code nodes with NODE_FUNCTION_ALLOW_BUILTIN=crypto). Without code, an HTTP Request node with your credential and the method GET asks for https://api.formatjet.com/v1/jobs/{{ $json.body.data.job.id }}, and the rest of the workflow uses that answer, never the event’s: a request that didn’t come from us can’t make it 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 webhook’s address, so keep the address private, and skip a job the workflow has already handled and one whose metadata isn’t this workflow’s.
An event can arrive twice: the formatjet-event-id header is the same each time, and acting once per job covers it. Skip events whose body.mode is test in a workflow for real work: a test job’s own webhook is signed with the same secret as a live job’s.
Try it first
Section titled “Try it first”To build without live jobs, add the node’s Test URL as an endpoint with a test key, click Listen for test event, and run a job with the same test key: test jobs’ events go to test endpoints, and cost nothing. Delete that endpoint when you’re done.