Asked 2 months ago by StellarAstronaut755
Configuring n8n HTTP Request Node for SendGrid Unsubscribe Pagination
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 2 months ago by StellarAstronaut755
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm working with SendGrid's unsubscribe endpoint (https://api.sendgrid.com/v3/suppression/unsubscribes) in n8n desktop and need to properly set up pagination using the node's built-in options. My goal is to use offset-based pagination (limit: 500, offset increases by 500) because the API returns navigation URLs in the Link header.
API Details
Endpoint: https://api.sendgrid.com/v3/suppression/unsubscribes
Pagination type: offset-based
Parameters:
• limit: 500
• offset: increments by 500
Current Response
The API includes pagination information in the Link header. For example:
JSON"link": "<https://api.sendgrid.com/v3/suppression/unsubscribes?%3Doffset=0&limit=500&offset=500>; rel=\"next\"; title=\"2\", <https://api.sendgrid.com/v3/suppression/unsubscribes?%3Doffset=0&limit=500&offset=0>; rel=\"prev\"; title=\"1\", <https://api.sendgrid.com/v3/suppression/unsubscribes?%3Doffset=0&limit=500&offset=30000>; rel=\"last\"; title=\"61\", <https://api.sendgrid.com/v3/suppression/unsubscribes?%3Doffset=0&limit=500&offset=0>; rel=\"first\"; title=\"1\""
What I’ve Tried
• Offset Pagination:
$pageCount * 500
for offset• URL Pagination:
• Complete Expression:
{{ !$response.headers.link?.includes(‘rel=\"next\"’) }}
How can I properly configure the HTTP Request node’s pagination settings to work with SendGrid’s API? Is there a way to leverage the next/prev/first/last URLs provided in the Link header with n8n’s built-in pagination options?
Comments 0
•Answers 1
•Views 43
Answer by TychoAI Agent • 14 days ago
Below is one approach you can take to let n8n handle SendGrid’s offset-based pagination correctly.
Set Pagination Mode:
In the HTTP Request node, first select Add Option > Pagination. Then choose the mode Update a Parameter in Each Request.
Configure Query Parameters:
"offset"
.JAVASCRIPT{{ $pageCount * 500 }}
Since $pageCount
starts at zero, the first request sends offset=0
, the second sends offset=500
, and so on.
Make Sure to Set the Limit:
While the pagination settings only update the offset, also include the query parameter limit
(set to 500
) as a fixed value so each request is correctly limited:
Under Send Query Parameters, add another parameter with:
Name: limit
Value: 500
Notes:
SendGrid returns a Link header with several URLs (next, prev, etc.). If you prefer to extract and use the next URL directly, do the following:
Set Pagination Mode:
In the node’s Pagination settings, choose Response Contains Next URL.
Extracting the Next URL:
In the Next URL field, use an expression that parses the link
header and returns the URL for rel="next"
. For example, you could use a regular expression to extract the URL:
JAVASCRIPT{{ $response.headers.link && $response.headers.link.match(/<([^>]+)>;\s*rel="next"/) ? $response.headers.link.match(/<([^>]+)>;\s*rel="next"/)[1] : null }}
This expression checks if the link
header exists and then extracts the URL that has the rel="next"
relation. If it finds no next URL, it returns null
and pagination stops.
Notes:
For Offset Pagination:
Use Update a Parameter in Each Request with the query parameter "offset"
set using the expression {{ $pageCount * 500 }}
and include the fixed limit=500
parameter.
For URL Pagination:
Use Response Contains Next URL and set the Next URL field to an expression that extracts the URL with rel="next"
from the Link header.
Either approach will let you paginate through SendGrid’s unsubscribe endpoint. Choose the one that best fits your scenario and testing results.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.