AutomationFlowsWeb Scraping › Fetch and Parse Amazon Sp-api Reports Into Structured Tsv Rows

Fetch and Parse Amazon Sp-api Reports Into Structured Tsv Rows

ByNexus AI @nexus-ai on n8n.io

This workflow manually requests an Amazon Selling Partner (SP-API) report, polls until it is ready, downloads the report document, optionally decompresses it if it is GZIP, and parses the TSV contents into one n8n item per row. Starts when you run the workflow manually. Uses…

Event trigger★★★★☆ complexity15 nodesHTTP RequestCompression
Web Scraping Trigger: Event Nodes: 15 Complexity: ★★★★☆ Added:

This workflow corresponds to n8n.io template #16399 — we link there as the canonical source.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "UJTTlhAclKbsiEwH",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true,
    "templateCredsSetupCompleted": true
  },
  "name": "Amazon SP-API: Fetch & Parse Report",
  "tags": [
    {
      "id": "IsOa8ESjBnjChWxj",
      "name": "amazon",
      "createdAt": "2026-06-16T12:12:54.678Z",
      "updatedAt": "2026-06-16T12:12:54.678Z"
    },
    {
      "id": "L0MIXHsN63oUPZFs",
      "name": "api",
      "createdAt": "2026-06-16T12:01:32.912Z",
      "updatedAt": "2026-06-16T12:01:32.912Z"
    },
    {
      "id": "00x02w9uHGy9hAoh",
      "name": "reporting",
      "createdAt": "2026-06-16T12:13:07.938Z",
      "updatedAt": "2026-06-16T12:13:07.938Z"
    },
    {
      "id": "3X1HvJSit9jTg7X3",
      "name": "ecommerce",
      "createdAt": "2026-06-16T12:13:10.304Z",
      "updatedAt": "2026-06-16T12:13:10.304Z"
    }
  ],
  "nodes": [
    {
      "id": "b0180fb5-df42-4ed0-b317-a9a5a332bd4e",
      "name": "Run Manually",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -208,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "9ee7b59e-e54f-4807-8b2f-7e7869f7e4f5",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "position": [
        0,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "cfg-endpoint",
              "name": "sp_api_endpoint",
              "type": "string",
              "value": "sellingpartnerapi-eu.amazon.com"
            },
            {
              "id": "cfg-report-type",
              "name": "report_type",
              "type": "string",
              "value": "GET_MERCHANT_LISTINGS_ALL_DATA"
            },
            {
              "id": "cfg-marketplace",
              "name": "marketplace_ids",
              "type": "string",
              "value": "A1805IZSGTT6HS"
            },
            {
              "id": "cfg-refresh",
              "name": "refresh_token",
              "type": "string",
              "value": ""
            },
            {
              "id": "cfg-client-id",
              "name": "client_id",
              "type": "string",
              "value": ""
            },
            {
              "id": "cfg-client-secret",
              "name": "client_secret",
              "type": "string",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "51240107-9fa1-41b2-80fc-31ac0ac1f19f",
      "name": "Get Access Token",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        208,
        0
      ],
      "parameters": {
        "url": "https://api.amazon.com/auth/o2/token",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "refresh_token"
            },
            {
              "name": "refresh_token",
              "value": "={{ $('Config').first().json.refresh_token }}"
            },
            {
              "name": "client_id",
              "value": "={{ $('Config').first().json.client_id }}"
            },
            {
              "name": "client_secret",
              "value": "={{ $('Config').first().json.client_secret }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "2e9bdbdc-e804-41bd-ae92-f044c97208b6",
      "name": "Create Report",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        464,
        0
      ],
      "parameters": {
        "url": "=https://{{ $('Config').first().json.sp_api_endpoint }}/reports/2021-06-30/reports",
        "method": "POST",
        "options": {},
        "jsonBody": "={{ JSON.stringify({ reportType: $('Config').first().json.report_type, marketplaceIds: [$('Config').first().json.marketplace_ids] }) }}",
        "sendBody": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "headerParameters": {
          "parameters": [
            {
              "name": "x-amz-access-token",
              "value": "={{ $('Get Access Token').first().json.access_token }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "55de0d4a-9ac5-4f63-af29-b223b1afb79a",
      "name": "Poll Until Done",
      "type": "n8n-nodes-base.code",
      "position": [
        672,
        0
      ],
      "parameters": {
        "jsCode": "// Poll Amazon SP-API until the report reaches a terminal status.\nconst reportId = $('Create Report').first().json.reportId;\nconst accessToken = $('Get Access Token').first().json.access_token;\nconst endpoint = $('Config').first().json.sp_api_endpoint;\n\nconst POLL_INTERVAL_MS = 10_000;\nconst MAX_ATTEMPTS = 30;\n\nlet lastResponse = null;\n\nfor (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {\n  const response = await this.helpers.httpRequest({\n    method: 'GET',\n    url: `https://${endpoint}/reports/2021-06-30/reports/${reportId}`,\n    headers: { 'x-amz-access-token': accessToken },\n    json: true,\n  });\n\n  lastResponse = response;\n\n  if (response.processingStatus === 'DONE') {\n    return [{ json: response }];\n  }\n  if (['FATAL', 'CANCELLED'].includes(response.processingStatus)) {\n    throw new Error('Report failed: ' + response.processingStatus);\n  }\n\n  await new Promise(r => setTimeout(r, POLL_INTERVAL_MS));\n}\n\nthrow new Error('Timed out after ' + MAX_ATTEMPTS + ' attempts. Last status: ' + lastResponse?.processingStatus);"
      },
      "typeVersion": 2
    },
    {
      "id": "f24e77fd-8ab4-4a6b-895c-3a7fb9401266",
      "name": "Get Report Document",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        0
      ],
      "parameters": {
        "url": "=https://{{ $('Config').first().json.sp_api_endpoint }}/reports/2021-06-30/documents/{{ $json.reportDocumentId }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-amz-access-token",
              "value": "={{ $('Get Access Token').first().json.access_token }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "59c2e1ed-cee4-42e5-b8cf-32316ac3f3c2",
      "name": "Download Report",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1136,
        0
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "2b82dc46-5ec5-4bc0-921f-3c22221289f5",
      "name": "Is Gzipped?",
      "type": "n8n-nodes-base.if",
      "position": [
        1328,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "cond-gz",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Get Report Document').first().json.compressionAlgorithm }}",
              "rightValue": "GZIP"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "3e100cac-5a0a-4313-bb79-9bc6d2f25014",
      "name": "Set GZ Extension",
      "type": "n8n-nodes-base.code",
      "position": [
        1536,
        -80
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nfor (const item of items) {\n  if (item.binary?.data) {\n    item.binary.data.fileExtension = 'gz';\n  }\n}\nreturn items;"
      },
      "typeVersion": 2
    },
    {
      "id": "69e508ab-1a3c-458d-9879-6178996eeaa9",
      "name": "Decompress",
      "type": "n8n-nodes-base.compression",
      "position": [
        1728,
        -80
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "1cdd0259-66fd-4ea3-9c74-090a416fe8ab",
      "name": "Parse Report TSV",
      "type": "n8n-nodes-base.code",
      "position": [
        1936,
        16
      ],
      "parameters": {
        "jsCode": "// Generic TSV parser for Amazon SP-API reports.\n// Works with any tab-separated report format.\nconst binary = $input.first().binary || {};\nconst binaryKeys = Object.keys(binary);\nif (binaryKeys.length === 0) throw new Error('No binary data on input');\n\nconst buf = await this.helpers.getBinaryDataBuffer(0, binaryKeys[0]);\nconst text = buf.toString('utf-8');\n\nconst lines = text.split(/\\r?\\n/).filter(l => l.trim().length > 0);\nif (lines.length < 2) throw new Error('Empty or header-only report');\n\nconst headers = lines[0].split('\\t').map(h => h.trim());\nconst rows = lines.slice(1).map(line => {\n  const cells = line.split('\\t');\n  const row = {};\n  headers.forEach((h, i) => row[h] = cells[i] !== undefined ? cells[i].trim() : '');\n  return row;\n});\n\n// Return each row as a separate n8n item for downstream processing\nreturn rows.map(row => ({ json: row }));"
      },
      "typeVersion": 2
    },
    {
      "id": "9c350d88-f0ce-4fa2-a8cb-02ef53f8d5bf",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1056,
        -224
      ],
      "parameters": {
        "width": 760,
        "height": 640,
        "content": "## Amazon SP-API: Fetch & Parse Report\n\n**For Amazon sellers and developers** who need to pull any SP-API report (listings, orders, inventory, etc.), handle GZIP decompression, and parse the TSV output into individual n8n items.\n\n### How it works\n1. **Config** sets credentials, endpoint, report type, and marketplace\n2. **Get Access Token** exchanges your refresh token for an access token via LWA\n3. **Create Report** submits a report request to Amazon\n4. **Poll Until Done** checks status every 10s, up to 5 minutes\n5. **Get Report Document** retrieves the download URL\n6. **Download Report** fetches the file as binary\n7. **Is Gzipped?** decompresses if needed\n8. **Parse Report TSV** outputs each row as a separate n8n item\n\n### Setup\n- [ ] Fill in your SP-API credentials in the **Config** node (refresh_token, client_id, client_secret)\n- [ ] Set sp_api_endpoint to your region (EU/NA/FE)\n- [ ] Set report_type and marketplace_ids\n- [ ] Run manually or replace the trigger with a Schedule node"
      },
      "typeVersion": 1
    },
    {
      "id": "039d82b3-d5e6-4b7a-a400-1de505db2a32",
      "name": "Section: Authentication",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -256,
        -224
      ],
      "parameters": {
        "color": 7,
        "width": 650,
        "height": 454,
        "content": "### Authentication\nExchange LWA refresh token for a short-lived access token used by all subsequent API calls."
      },
      "typeVersion": 1
    },
    {
      "id": "5a6faf2c-78d2-4c86-b96e-524144a1b5e7",
      "name": "Section: Report Request & Polling",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        432,
        -224
      ],
      "parameters": {
        "color": 7,
        "width": 614,
        "height": 454,
        "content": "### Report Request & Polling\nSubmit a report request to Amazon, then poll every 10 seconds (up to 5 min) until the report is ready."
      },
      "typeVersion": 1
    },
    {
      "id": "c19e0ca2-115a-40d1-88aa-8ea345ec7e35",
      "name": "Section: Download & Parse",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1088,
        -224
      ],
      "parameters": {
        "color": 7,
        "width": 1030,
        "height": 446,
        "content": "### Download & Parse\nFetch the report file, decompress if GZIP-encoded, and split the TSV into individual n8n items."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "58a9f20d-37dc-434d-80ff-dbd8b284f982",
  "nodeGroups": [],
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Get Access Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decompress": {
      "main": [
        [
          {
            "node": "Parse Report TSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Gzipped?": {
      "main": [
        [
          {
            "node": "Set GZ Extension",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Parse Report TSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Manually": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Report": {
      "main": [
        [
          {
            "node": "Poll Until Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Report": {
      "main": [
        [
          {
            "node": "Is Gzipped?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll Until Done": {
      "main": [
        [
          {
            "node": "Get Report Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Access Token": {
      "main": [
        [
          {
            "node": "Create Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set GZ Extension": {
      "main": [
        [
          {
            "node": "Decompress",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Report Document": {
      "main": [
        [
          {
            "node": "Download Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow manually requests an Amazon Selling Partner (SP-API) report, polls until it is ready, downloads the report document, optionally decompresses it if it is GZIP, and parses the TSV contents into one n8n item per row. Starts when you run the workflow manually. Uses…

Source: https://n8n.io/workflows/16399/ — original creator credit. Request a take-down →

More Web Scraping workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

Web Scraping

This workflow automatically converts each page of a multi-page PDF into high-quality PNG images. It uses the PDF.co API in the background to process the PDF and generate individual images for every pa

HTTP Request, Compression
Web Scraping

file manager. Uses s3, n8n-nodes-text-manipulation, compression, httpRequest. Event-driven trigger; 11 nodes.

S3, N8N Nodes Text Manipulation, Compression +2
Web Scraping

Workflow 1621. Uses httpRequest, compression. Event-driven trigger; 6 nodes.

HTTP Request, Compression
Web Scraping

This workflow listens for an “Approved” label on a Trello card, reads the AI draft bookkeeping JSON from card comments, and posts the corresponding transaction to Xero. It then adds a Xero deep link b

Trello Trigger, HTTP Request
Web Scraping

02_LLM_Pipeline v1.0. Uses executeWorkflowTrigger, httpRequest, seaTable. Event-driven trigger; 65 nodes.

Execute Workflow Trigger, HTTP Request, Sea Table