Skip to content
Guides

Poll a paginated REST API

Read a REST API that pages its results with a polling trigger, run each new or changed record once, handle dates that do not sort as text, and run everything again when you need to.

On this page

Many REST APIs return their results a page at a time: 50 records and a token or a link for the next page. This guide sets up a polling trigger on such an API. Each poll follows every page, and each new or changed record runs the workflow once.

sequenceDiagram
    participant Engine as MedHook engine
    participant API as Appointments API (test)

    loop Every interval
        Engine->>API: GET /appointments?updatedSince={cursor}
        API-->>Engine: page 1 + nextPageToken
        Engine->>API: GET /appointments?updatedSince={cursor}&pageToken=…
        API-->>Engine: last page (no token)
    end
    Engine->>Engine: One execution per new or changed record

Before you start

  • A running engine and a signed-in user. See the Quick start.
  • A REST API that pages its results. This guide uses https://api.example.test, which answers GET /appointments with up to 50 records and, when there are more, a token for the next page:
json
{
  "data": [
    {
      "id": "apt-2001",
      "status": "booked",
      "start": "2026-11-20T09:30:00Z",
      "updatedAt": "2026-11-12T14:02:11Z",
      "patient": {
        "mrn": "TEST000123",
        "family": "TESTPATIENT",
        "given": "ALPHA"
      }
    }
  ],
  "nextPageToken": "eyJwYWdlIjoyfQ"
}

The API takes updatedSince to return only records changed after a time, and pageToken for the next page.

How a poll decides what is new

A poll can read the same record many times. Three settings decide whether it runs again:

  • Id field names each record's id, id by default. A record without one is keyed by a fingerprint of the whole record, so any change to it makes it a new record.
  • Cursor field names a value that grows with each change, such as updatedAt. A record runs when its value is past the stored cursor, so a later change to the same record runs again and the same change never runs twice. Without a cursor field, the engine remembers the last 5,000 ids it ran and skips those.
  • Every record that runs also leaves a duplicate receipt for 24 hours, keyed by its id and its cursor value. A change to the trigger that starts the cursor again still skips records that ran in that window.

Always set a cursor field when the API has one. See Duplicates and the cursor.

Steps

1. Create the connection

Open Adapters and choose New connection. Pick Generic REST, name it Appointments API, set Base URL to https://api.example.test and the Auth type the API needs, then save. The engine refuses a base URL on a private address unless the operator allows it. See Generic REST.

2. Set up the polling trigger

Create a workflow as in Pull from an API to HL7v2 over MLLP, then select the Source step, set Trigger type to polling and fill in:

FieldValue
Interval (seconds)60, or as low as 10 while you test
Adapter profileAppointments API · generic-rest
Actionread
Paramsthe JSON below
Items pathempty: with pagination, the items are found on each page
Max items per pollabove the number of changed records you expect between two polls (default 100)
Cursor fieldupdatedAt
Cursor formatas is (sorts as text or numbers): ISO-8601 times sort as text. See step 3
Id fieldid (the default)
First pollnow to skip what is already there, or beginning to run it

Params:

json
{
  "endpoint": "/appointments",
  "query": { "updatedSince": "{{cursor}}" },
  "pagination": {
    "mode": "next-token",
    "itemsPath": "$.data",
    "nextPath": "$.nextPageToken",
    "param": "pageToken"
  }
}

{{cursor}} becomes the newest updatedAt the workflow has already run, so each poll asks only for what changed. Before there is a cursor, on the first poll, updatedSince is left out and the API returns everything.

The pagination block tells the read how the API pages. itemsPath is where the records are on each page, and nextPath is where the next page's token is. Pick the mode that matches the API:

ModeThe API givesSettings
next-urlthe next page's URL in the bodynextPath
next-tokena token in the body, sent back as a query parameternextPath, param (default pageToken)
cursora cursor in the body, sent back as a query parameternextPath, param (default cursor)
link-headera Link header with rel="next"none
offsetpages by offset and limitoffsetParam (offset), limitParam (limit), limit (100); stops at a short page
pagepages by numberparam (page), startPage (1); stops at an empty page, or a short one when pageSize (sent as pageSizeParam) is set

Without itemsPath, a page's items are the body itself when it is a list, or its items field. In cursor mode, put the poll's {{cursor}} in query, as above: in a urlTemplate, {{cursor}} is the page cursor.

How the pages are read:

  • One poll follows every page, up to 50 by default. Set maxPages in the pagination block for an API with more.
  • A page that answers 429 or a 5xx, or drops the connection, is tried again on its own, waiting out the API's Retry-After. The pages already read are not read again.
  • A next-page URL (next-url and link-header) must stay on the first page's host. A link to another host fails the read, so the profile's credentials never go anywhere else.
  • If a poll stops at maxPages before the last page, it runs what it read only when the records are in cursor order. Sort the API's results by the cursor field, oldest first, when the API lets you.

3. Dates that do not sort as text

The engine compares cursor values as numbers when they are numbers, and as text otherwise. ISO-8601 times (2026-11-12T14:02:11Z) and sequence numbers sort correctly. A date written another way does not: as text, 01/02/2027 comes before 12/31/2026, so records around a month or year change are skipped or run again.

When the cursor field holds such a date, set Cursor format to how it is written:

Cursor format (stored value)Shown in the builder asExample
MM/DD/YYYYMM/DD/YYYY11/12/2026
MM/DD/YYYY HH:mmMM/DD/YYYY HH:mm11/12/2026 14:02
MM/DD/YYYY HH:mm:ssMM/DD/YYYY HH:mm:ss11/12/2026 14:02:11
MM/DD/YYYY hh:mm AMM/DD/YYYY hh:mm AM/PM11/12/2026 02:02 PM
MM/DD/YYYY hh:mm:ss AMM/DD/YYYY hh:mm:ss AM/PM11/12/2026 02:02:11 PM
DD/MM/YYYYDD/MM/YYYY12/11/2026
DD/MM/YYYY HH:mm:ssDD/MM/YYYY HH:mm:ss12/11/2026 14:02:11
YYYYMMDDHHmmssHL7 date/time20261112140211
epoch-secondsepoch seconds1794492131
epoch-millisepoch milliseconds1794492131000

The engine reads each value in that format and stores the cursor as an ISO-8601 time. {{cursor}} in Params gets it back in the API's own format, such as 11/12/2026 14:02:11. A value without a time zone is compared as the clock time it shows, never converted. A record whose value does not parse in the format does not run, and the poll logs how many there were.

A date-only format, such as MM/DD/YYYY, sees only whole days. Records changed later on the cursor's day have the same cursor value, so the API's filter must ask for records on or after the cursor date, not after it. The engine remembers the ids it already ran on that date and skips them.

Changing Cursor format starts the cursor again, as changing the cursor field does.

4. Read each record in your steps

Each record runs as its own execution, and its steps get { triggerType: "polling", triggerId, item, polledAt }. The record is input.item, so a JavaScript step reads input.item.patient.mrn, not input.patient.mrn.

To test, choose Load sample, then Paste a sample, paste one record as the API returns it and choose Run test. It runs the sample as a poll would, with the record as input.item. Then add a destination and deploy, as in Pull from an API to HL7v2 over MLLP.

The first poll runs within a few seconds of the deploy, then once per interval. Each record is one row in Messages, with the source polling.

Run everything again

To run records again that already ran, open the workflow's Settings, then Delivery, and choose Poll from the beginning on the Polling cursor card. Confirm it. The engine forgets the cursor, the ids it remembers and the duplicate receipts. The next poll, within a few seconds, runs every record the API returns, whatever First poll says.

  • The records really run again: every destination receives them a second time.
  • A poll in progress is never interrupted. If one is running, the reset says so; try again a few seconds later.

To run only a few messages again, find them in Messages and choose Replay instead. See Replay and Edit & replay.

Polling, a schedule or a batch run

Polling triggerScheduleBatch run
Use it fornew and changed records, as they appeara full sweep of the API at set timesa large backfill, once
Between runskeeps a cursor, so each record runs once per changeremembers nothing: each run reads every page againkeeps a checkpoint until the batch ends
How you set it upthis guidethe Scheduled REST API sweep template: a paginated read, then a Loop step over $.itemsPOST /api/batch-runs
How much per runMax items per poll; the rest run on the next polla loop runs at most 1,000 recordsthe whole result, a chunk at a time

See The schedule type and Large batches.

Troubleshooting

Is my poller running? Open the workflow's Overview and look at Recent polls. The summary reads like Last 10 polls, about every 60 s: all OK · 25 items each · 0 new: every poll is listed, with the items it read, how many were new and how many had already run, even when nothing new ran. Choose Request on a row to see that poll's request and the API's response, masked, in the connection's Calls tab. A paginated read is one row there, with the first page's response; the row on Recent polls says how many pages the poll read. See Recent polls.

Which polls failed yesterday? In the connection's Calls tab choose Polls and Failed, then Load older calls until you reach yesterday: each failed read shows its status and the API's masked response. The tab keeps 7 days of calls by default, so a failure from the weekend is still there on Monday.

  • No polls are listed. The workflow is off, or it has not been deployed with the polling trigger. A card that says poll history is off means the event log or its trigger family is turned off on this engine.
  • Polls are listed but further apart than the interval. Each poll waits for the one before it to finish: a slow API or many pages make the gap longer. A Skipped row means the workflow's backlog or max in flight held the poll back.
  • Every poll reads items but 0 are new. That is expected once they have run: the engine runs each item once. To run them again, use Poll from the beginning.

When a poll fails, the workflow's Overview shows Polling is failing with the reason and the last poll that read the source, and the Polling cursor card under Settings › Delivery shows the last error. A poll that fails writes no message, so start there.

  • Nothing runs after the first deploy. With First poll set to now, the first poll only records what is there, and only later changes run. Change a record in the API, or use Poll from the beginning. First poll applies only when the cursor starts, so set it before the first deploy.
  • Nothing runs, and the API has records. Items path is set on the trigger while Params has pagination. Clear it and put the path in the pagination block's itemsPath.
  • Every poll runs the same records again. The API ignores the updatedSince filter and there is no Cursor field. Set the cursor field, or make the API filter by the cursor.
  • Run test works but live runs fail with Cannot read properties of undefined. The steps read the record's fields from input instead of input.item.
  • Records around the first of the month are skipped or run twice. The cursor field holds a date that does not sort as text, such as MM/DD/YYYY. Set Cursor format. With a date-only format, make the API's filter on or after the cursor date.

Reference