API to API
A signed JSON webhook in, checked against a JSON Schema, mapped per sender, posted to a REST API with OAuth2, and answered with the API's response. Plus the polling variant for an API that can't push.
On this page
Each Demo Health clinic posts new appointments to MedHook as JSON. MedHook checks the body, maps it to the scheduling API's JSON with that clinic's settings, posts it with an OAuth2 token, and answers the clinic with the scheduling API's confirmation. A failed call is answered at once, and you replay it from the engine when the API is back.
Source and destination
sequenceDiagram
participant Clinic as Demo Health clinic
participant Engine as MedHook engine
participant Token as Token endpoint
participant API as Scheduling API
Clinic->>Engine: POST /api/triggers/webhook/demo-health-appointments (signed JSON)
Engine->>Engine: Signature, timestamp, JSON Schema
Engine->>Engine: Data map with the sender's settings
Engine->>Token: client_credentials (once, then cached)
Token-->>Engine: access_token
Engine->>API: POST /accounts/{accountId}/appointments
API-->>Engine: 201 { id, status }
Engine-->>Clinic: 201 { confirmation, status }- Source: a webhook trigger with a signing secret, a body schema,
senderFromandresponse.modedestination. - Destination: one Generic REST step, action
post, with OAuth2 client credentials. - Per sender: the workflow's sender table holds each clinic's
accountIdand defaultclinicCode.
What it uses
- Signing and the replay window.
- Validating the body.
- JSON senders and per-sender settings.
- The field-mapping step.
- Answering the sender with a step's output.
- The Delivered tab and replay.
Status
Available on this release. An automated test runs this recipe's workflow file against a local token endpoint and a local scheduling API on every change.
The workflow file
Import the workflow file under Workflows, then Import › Import JSON. It holds the trigger, the three steps and their settings. It has no credentials: you add the signing secret and choose the adapter profile in the steps below.
The body the clinics send:
{
"sender": "dh-north",
"appointmentId": "APT-1001",
"start": "2026-11-02T09:30:00Z",
"durationMinutes": 20,
"reminder": "sms",
"patient": { "mrn": "TESTMRN0001", "family": "TESTPATIENT", "given": "ALEX" }
}Steps
-
Under Adapters, create a Generic REST profile named
Scheduling API: base URLhttps://scheduling.example.test/api/v1, authenticationoauth2, with the client id, client secret and token URL (https://scheduling.example.test/oauth/token) the API owner gave you. The engine fetches a token with the client credentials grant, caches it until it expires, and fetches a new one once if the API answers 401.Auth0, Okta and Azure AD often want more: set OAuth2 audience (
oauth2Audience) to the API's identifier, OAuth2 client auth toclient_secret_postwhen the token endpoint reads the secret from the form, or chooseoauth2-private-key-jwtand give the profile a private key instead of a secret. See OAuth2. -
Import the workflow file. On Post to the scheduling API, choose
Scheduling API. Its endpoint is/accounts/{{sender.accountId}}/appointments. -
On the trigger, keep Webhook id
demo-health-appointmentsor choose your own, and set a signing secret through the API ("secret": "whsec_..."). Signed timestamp is required, so a captured request can't be sent again later. -
Choose Settings, and under Delivery, in Senders, write one line per clinic.
senderFromreads thesenderfield of the body, so these keys are the values clinics send:textdh-north: accountId=acct-north; clinicCode=NORTH-01 dh-south: accountId=acct-south; clinicCode=SOUTH-01Choose Save senders.
-
Deploy the workflow.
-
Give each clinic the URL
https://engine.example.test/api/triggers/webhook/demo-health-appointmentsand the signing secret. They sign with Standard Webhooks headers (webhook-id,webhook-timestamp,webhook-signature), which most webhook libraries send.
What the steps do
Map to the scheduling API is a data map from the clinic's JSON to the API's JSON:
| Source | Target | Notes |
|---|---|---|
$.data.appointmentId | externalId | |
$.data.patient.mrn | patient.identifier | |
$.data.patient.family | patient.lastName | |
$.data.patient.given | patient.firstName | |
$.data.start | slot.start | |
$.data.durationMinutes | slot.minutes | 30 when the clinic leaves it out |
$.data.clinicCode | slot.clinic | The sender's clinicCode when the body has none |
$.data.reminder | reminderChannel | sms becomes TEXT, email becomes EMAIL, anything NONE |
Post to the scheduling API posts the map's output as JSON. The engine adds an Idempotency-Key header that stays the same when it sends the same step for the same message again, so an API that honours it drops a resend.
To change an appointment the API already has, send to its own URL: a Generic REST step with action put (or patch, delete) and "urlTemplate": "/appointments/{{data.id}}" in place of endpoint. The id comes from the step's input, encoded as one path segment, and can't change the host. See URL templates.
When the API answers 201 for a booking and 202 for one it queued, set the post step's response to full. Its output is then { "status", "headers", "body" }, and a condition step after it branches on data.status === 201; the Location header is data.headers.location. See The response.
Answer the clinic maps the API's response, { "id": "CONF-...", "status": "booked" }, to { "confirmation": "CONF-...", "status": "booked" }. The trigger answers the clinic with this step's output and status 201, once the run ends.
Test it
- A signed body from
dh-northgets201 { "confirmation": "CONF-...", "status": "booked" }. The scheduling API receivesPOST /api/v1/accounts/acct-north/appointmentswithAuthorization: Bearer <token>andslot.clinicNORTH-01. - A body from
dh-southwith"clinicCode": "SOUTH-07"goes toacct-southwithslot.clinicSOUTH-07. The token endpoint is called once for both. - A body without
patient.mrnand with"start": "next tuesday"gets 400BODY_SCHEMA_INVALIDwith"/patient/mrn: is required"and"/start: must be a date-time (RFC 3339)". Nothing is sent. - An unsigned body gets 403. A signed body with a timestamp from 15 minutes ago gets 401
TIMESTAMP_OUT_OF_TOLERANCE. - In Messages, open a run and choose Delivered: the host,
POST, status 201, the request and response bodies, and theAuthorizationheader shown as[redacted]. Its Correlation id is the clinic'sx-request-id, which the scheduling API received asX-Request-Id; a clinic that sends none gets the engine's id back in the response'sX-Request-IDheader.
When the API fails
When the scheduling API answers 503, the run fails and the clinic gets 502 with the execution id, never the error text. The workflow file sets Workflow retries to 0, so the clinic decides whether to resend. Raise it to have the engine retry first: the clinic then gets the answer of the last attempt, within the trigger's 20-second wait.
The failed run is on Messages › Needs action. Once the API is back, choose Replay on it, or call POST /api/executions/{id}/replay. The replay runs the same message again, with the same sender settings, and the API receives it once.
The polling variant
When the source can't push, poll it. A polling trigger on a Generic REST profile reads the API on a schedule, follows its pages, and runs the workflow once per new item. It keeps a cursor in PostgreSQL between polls, so each poll reads only what changed, across restarts and replicas.
{
"type": "polling",
"interval": 60000,
"adapterProfileId": "<the source API's profile>",
"action": "get",
"params": {
"urlTemplate": "/appointments?updatedSince={{cursor}}",
"pagination": {
"mode": "next-token",
"itemsPath": "$.data",
"nextPath": "$.nextPageToken",
"param": "pageToken"
}
},
"idField": "id",
"cursorField": "updatedAt",
"startFrom": "beginning"
}Each item then runs the same kind of steps: a data map, or a JavaScript step that builds an HL7v2 message for an MLLP send, or a BigQuery insert. The page's itemsPath sits inside pagination: the trigger's own Items path stays empty. See Poll a paginated REST API for the setup, Polling for the cursor rules, Pull from an API to HL7v2 over MLLP for the HL7v2 destination, and FHIR Bulk to a warehouse for BigQuery.