Hi I’m trying to build an autmated foreacast and stock ordering system to run on a weekly basis. I need to gather all the data in and I am struggling with Shoplify. to automate the process I need dynamic dates. I am a beginner and building using AI to write code and guide me but I’m getting stuck!
Workflow starts wirh an initialize pagination node. I have a function node with dates and query, then I have Http request for shopify (I know the auth is working because a certain points I have data coming out but never more than 250 records) intheory it should loop 3 times I Know it should be 520ish records/orders. Following on I have a function node which holds data and passes through the page info then I have an if node to send round loop back to function query node.
Issue: I cant get HTTP node to give me more than 250 records and now it won’t even give me data!! ANy advice please?
type {
"nodes": [
{
"parameters": {},
"id": "dcf74a79-eaa8-4499-a502-8750f9e99341",
"name": "Weekly Order Trigger",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
0,
0
]
},
{
"parameters": {
"jsCode": "// Get edges and pageInfo from the current HTTP response\nconst edges = $json?.data?.orders?.edges ?? [];\nconst pageInfo = $json?.data?.orders?.pageInfo ?? { hasNextPage: false, endCursor: null };\n\n// Use a consistent variable name for accumulating all data\nconst store = $getWorkflowStaticData('global');\nif (!store.allCollectedItems) store.allCollectedItems = [];\n\n// Extract and accumulate orders (or just line items if that's the final goal for this part)\n// Your original code was extracting line items. Let's make sure it accumulates full orders for now.\n// If you only need line items, you can stick to your original line item extraction.\n// For full orders:\nconst currentOrders = edges.map(edge => {\n const orderNode = edge.node;\n // Optionally, flatten line items here if you prefer\n const lineItems = orderNode.lineItems?.edges?.map(liEdge => liEdge.node) || [];\n return {\n id: orderNode.id,\n name: orderNode.name,\n createdAt: orderNode.createdAt,\n displayFinancialStatus: orderNode.displayFinancialStatus,\n // ... include other order fields you need\n lineItems: lineItems // Keep line items nested for now\n };\n});\nstore.allCollectedItems.push(...currentOrders);\n\n// Output only pagination info for the next node\nconst output = {\n hasNextPage: pageInfo.hasNextPage === true,\n nextCursor: pageInfo.endCursor\n};\n\nreturn [{ json: output }];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
880,
0
],
"id": "a2ff3858-3be2-4acc-b86f-96dfbb93d4e7",
"name": "Process Shopify Orders & Pagination"
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 1
},
"conditions": [
{
"id": "018220be-00c8-41ac-93e0-b09d8f2f3057",
"leftValue": "=={{ $json.hasNextPage }}",
"rightValue": "true",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"name": "More Shopify Pages?",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
1080,
0
],
"id": "c7d2ff5b-81f2-4ce9-99ca-8b4b81988d5e"
},
{
"parameters": {
"jsCode": "// Get all accumulated Shopify orders\nconst store = $getWorkflowStaticData('global');\nconst allOrders = store.shopifyOrders || [];\n\n// Group by SKU\nconst skuMap = {};\nfor (const item of allOrders) {\n const sku = item.sku;\n if (!skuMap[sku]) {\n skuMap[sku] = {\n sku: sku,\n title: item.title,\n shopify_quantity: 0,\n source: 'Shopify'\n };\n }\n skuMap[sku].shopify_quantity += item.quantity;\n}\n\n// Clear stored data for next run\nstore.shopifyOrders = [];\n\n// Return consolidated data\nreturn Object.values(skuMap).map(item => ({ json: item }));"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1320,
20
],
"id": "dbfe7829-047a-45e4-aebe-6a0fe310c614",
"name": "Consolidate Shopify Sales by SKU"
},
{
"parameters": {
"functionCode": "// Function to format a date to 'YYYY-MM-DDTHH:MM:SSZ' (UTC, no milliseconds)\nfunction formatShopifyDateISO(date) {\n return date.toISOString().slice(0, 19) + 'Z';\n}\n\nconst daysBack = 30;\n\nconst startDate = new Date();\nstartDate.setDate(startDate.getDate() - daysBack);\nstartDate.setHours(0, 0, 0, 0);\n\nconst endDate = new Date();\nendDate.setHours(23, 59, 59, 999);\n\nconst isoStart = formatShopifyDateISO(startDate);\nconst isoEnd = formatShopifyDateISO(endDate);\n\n// Determine the 'after' cursor for pagination.\n// This will be null for the first run, then the actual cursor from the previous page\nconst afterCursor = $json.nextCursor ? $json.nextCursor : null;\n\n// Construct the search query string for Shopify's 'query' parameter\nconst shopifySearchQuery = `created_at:>=${isoStart} created_at:<=${isoEnd}`;\n\n// The GraphQL query string\nconst query = `\nquery ($after: String, $searchQuery: String!) {\n orders(first: 250, after: $after, query: $searchQuery) {\n edges {\n node {\n id\n name\n createdAt\n displayFinancialStatus\n tags\n fulfillments {\n id\n status\n createdAt\n }\n lineItems(first: 50) {\n edges {\n node {\n quantity\n title\n sku\n originalTotalSet {\n shopMoney {\n amount\n currencyCode\n }\n }\n product {\n id\n title\n }\n variant {\n id\n sku\n title\n }\n }\n }\n }\n }\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n}\n`;\n\n// Return the query string and the variables object in a 'json' property\nreturn [{\n json: {\n query: query,\n variables: {\n after: afterCursor,\n searchQuery: shopifySearchQuery\n }\n }\n}];"
},
"id": "9efe9880-977d-441e-b0df-fce87f4c7909",
"name": "Build Shopify Query1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
500,
0
]
},
{
"parameters": {
"authentication": "headerAuth",
"requestMethod": "POST",
"url": "https://Rawbean.myshopify.com/admin/api/2025-04/graphql.json",
"options": {
"batchSize": 250,
"bodyContentType": "raw",
"fullResponse": false,
"splitIntoItems": false
},
"bodyParametersUi": {
"parameter": [
{
"value": "=={{ JSON.stringify($json.json) }}"
}
]
},
"headerParametersUi": {
"parameter": [
{
"name": "Content-Type",
"value": "application/json"
}
]
}
},
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 1,
"position": [
680,
0
],
"id": "42eef2e1-0ed2-4b34-a744-69fdca3a9647",
"credentials": {
"httpHeaderAuth": {
"id": "DvQ0B24VIOwned70",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"jsCode": "const store = $getWorkflowStaticData('global');\n// Clear any accumulated data from previous runs\nstore.shopifyOrders = []; // Or store.allOrders if that's the one you use\nstore.allCollectedItems = []; // A general place to store all items\n\n// Initialize pagination state for the first API call\nreturn [{\n json: {\n nextCursor: null, // No cursor for the first page\n hasNextPage: true // Assume there's at least one page\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
200,
0
],
"id": "3e3bdd1c-9029-4c74-bcee-357586eebac8",
"name": "initialize pagination"
}
],
"connections": {
"Weekly Order Trigger": {
"main": [
[
{
"node": "initialize pagination",
"type": "main",
"index": 0
}
]
]
},
"Process Shopify Orders & Pagination": {
"main": [
[
{
"node": "More Shopify Pages?",
"type": "main",
"index": 0
}
]
]
},
"More Shopify Pages?": {
"main": [
[
{
"node": "Build Shopify Query1",
"type": "main",
"index": 0
}
],
[
{
"node": "Consolidate Shopify Sales by SKU",
"type": "main",
"index": 0
}
]
]
},
"Build Shopify Query1": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request": {
"main": [
[
{
"node": "Process Shopify Orders & Pagination",
"type": "main",
"index": 0
}
]
]
},
"initialize pagination": {
"main": [
[
{
"node": "Build Shopify Query1",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {
"Weekly Order Trigger": [
{}
]
},
"meta": {
"instanceId": "9255ae7d765452c66754e7eccf7e1d08906e7fb23072821508fd261cbb99b75c"
}
}or paste code here