REST Block
This Utility Block is used to make REST API calls. If you require more features, you can use the Axios module from the Javascript Block.
The Block shows the current configuration, which can be changed by pressing the Edit button.
Method
The usual REST method (GET, POST, PUT, PATCH, DELETE) should be selected from the dropdown.
URL
The URL can contain query and path parameters. These can be literal values but you can also insert tokens in the format token.qualifier
.
Token references
Token | Description |
---|---|
$ | References data on the input edge. {$} = full edge data {$.limit} = the value of the limit key |
variables | Replace token with a variable value, e.g. {variables.limit} |
secrets | Replace token with a secret value, e.g. {secrets.apiKey} |
batch | Used for limit/offset and cursor pagination (see below) |
Pagination
If you want to paginate your REST calls, then you should check the Loop until no data box. This will process in batches (make sure you have a Batch End block to close the loop).
Using offset/limit
If the API expects offset and limit values, then you would include something like the following in the URL:
&limit=100
&limit={$.limit}
(takes the value from the input edge data)&offset={batch.offset}
(managed internally, you don’t need to set it)
Using a pagination cursor
Some APIs use a cursor, in which case you need to tell Ziggy where to find the cursor in the response data. Several HubSpot APIs return a cursor at paging.next.after
.
Include it in the URL like this:
&after={batch.paging||"!remove!"}
Using !remove!
Some API endpoints may not function correctly if a query parameter is empty.
For example, HubSpot APIs that support pagination will error if you pass &after=
or after=''
. In other words, if the after
parameter, if used, must contain a value.
To solve this, add !remove!
. It strips the query parameter if it's empty:
&after={batch.paging||"!remove!"}
Headers
You can add or remove headers from the edit dialog. Tokens are supported ($
, variables
, secrets
, batch
).
Body
Specify a token to indicate where the body data should come from. This will often be an {input.path}
token.
Response data path
Once the response payload has been received, you should specify the object path to the data that should be placed on the output edge.
For example, if the returned object looks like this:
{
results: [some data array],
paging: {
next: {
after: '876128763'
}
}
}
You would specify results
as the data path.
If left empty, the root object is placed on the output edge by default.
Batching
If you are fetching large quantities of data, you will usually need to use some form of pagination.
Enable pagination by checking Loop until no data.
URL query parameters
Supported approaches:
limit
andoffset
query or path parameters- Cursor pagination
Use one of the following tokens:
{batch.offset}
or
{batch.paging}
Cursor Pagination
If the API is using cursor pagination, specify the response data path to the cursor key.
In the above example, this is paging.next.after
.
Batch End Block
Include a Batch End Block downstream of the REST Block as the loop back point. You can include other Blocks in between.