Although the general idea of a loop is helpful, in the case of working with the Square API, I needed to do an initial fetch and then to filter based on whether the response JSON returned a cursor and use the cursor for the rest of the HTTP requests. This is a working example of that.
{
"nodes": [
{
"parameters": {
"functionCode": "return items.filter(i => i.json.cursor)"
},
"name": "Filter Cursor",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
630,
370
]
},
{
"parameters": {},
"name": "Merge",
"type": "n8n-nodes-base.merge",
"typeVersion": 1,
"position": [
930,
320
]
},
{
"parameters": {
"authentication": "oAuth2",
"url": "https://connect.squareup.com/v2/catalog/list",
"options": {},
"headerParametersUi": {
"parameter": [
{
"name": "Content-type",
"value": "application/json"
}
]
},
"queryParametersUi": {
"parameter": [
{
"name": "types",
"value": "ITEM,ITEM_VARIATION,CATEGORY,IMAGE,ITEM_OPTION,ITEM_OPTION_VAL,DISCOUNT,TAX,MODIFIER,MODIFIER_LIST"
}
]
}
},
"name": "Initial Fetch",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
450,
300
],
"credentials": {
"oAuth2Api": "Square"
}
},
{
"parameters": {
"authentication": "oAuth2",
"url": "https://connect.squareup.com/v2/catalog/list",
"options": {},
"headerParametersUi": {
"parameter": [
{
"name": "Content-type",
"value": "application/json"
}
]
},
"queryParametersUi": {
"parameter": [
{
"name": "types",
"value": "ITEM,ITEM_VARIATION,CATEGORY,IMAGE,ITEM_OPTION,ITEM_OPTION_VAL,DISCOUNT,TAX,MODIFIER,MODIFIER_LIST"
},
{
"name": "cursor",
"value": "={{$json.cursor}}"
}
]
}
},
"name": "Fetch Page",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
760,
560
],
"executeOnce": true,
"credentials": {
"oAuth2Api": "Square"
}
},
{
"parameters": {},
"name": "Output",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1110,
320
]
}
],
"connections": {
"Filter Cursor": {
"main": [
[
{
"node": "Fetch Page",
"type": "main",
"index": 0
}
]
]
},
"Merge": {
"main": [
[
{
"node": "Output",
"type": "main",
"index": 0
}
]
]
},
"Initial Fetch": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
},
{
"node": "Filter Cursor",
"type": "main",
"index": 0
}
]
]
},
"Fetch Page": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
},
{
"node": "Filter Cursor",
"type": "main",
"index": 0
}
]
]
}
}
}