{
  "name": "Amazon Best Sellers rank history to Google Sheets",
  "nodes": [
    {
      "id": "206b9ed9-912b-5881-87cf-595108aa4ae0",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -720,
        0
      ],
      "parameters": {
        "content": "## Amazon Best Sellers rank history to Google Sheets\n\n### How it works\nFor Amazon sellers, brands and analysts who want a day-by-day Best Sellers history. Every day at 07:00, the workflow runs the [Amazon Best Sellers Scraper](https://apify.com/aurelix/amazon-best-sellers) Actor on Apify and reads the Best Sellers top 100 of your categories and appends every product with its rank, previous rank, rank change and new-entry flag to a Google Sheet, so the sheet becomes a rank history.\n\n### Setup\n1. Install the **Apify** node (verified community node: on n8n Cloud search *Apify* in the nodes panel and click Install; self-hosted: Settings > Community nodes > `@apify/n8n-nodes-apify`). Create an **Apify API** credential with your API token (Apify Console > Settings > API & Integrations) and select it on the Apify node. Tested with `@apify/n8n-nodes-apify` 0.9.0 on n8n 2.46; install guide: https://docs.apify.com/platform/integrations/n8n\n2. Create a **Google Sheets OAuth2** credential and select it on **Append rows to sheet**. Make a sheet tab (name in the Set node) whose header row is the column list in the Deliver note.\n3. Open **Set search** and change the values: what to search, the Google Sheets target, and `maxChargeUsd`, the most one run may cost.\n4. Run once by hand, check the result, then activate.\n\n### Cost\nAbout $0.075 per run at most on Apify's free plan for 100 products (one category, both pages); `maxChargeUsd` caps every run.\n\n### Limitations\nNeeds an Apify account (Apify bills the Actor's results to it) and the Apify community node. Runs that fail or hit `maxChargeUsd` stop the workflow at the Apify node; check the run in Apify Console.\n\n### Customization\nAdd categories to `categories` (one history per category list), or use `amazonDomain` `ca`, `co.uk`, `de` and others. In the sheet, filter `rank_change` to see the day's biggest movers.",
        "height": 860,
        "width": 640
      }
    },
    {
      "id": "cc915ba8-c6a4-53ff-a392-d4804e8049c6",
      "name": "Run the Actor",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        220,
        140
      ],
      "parameters": {
        "content": "## Run the Actor\nEdit the search and the spend cap in **Set search**. The Apify node waits for the run and returns its results.",
        "height": 340,
        "width": 540,
        "color": 7
      }
    },
    {
      "id": "0cca1f03-c52d-57c2-952e-b5475f79ac25",
      "name": "Deliver",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        740,
        140
      ],
      "parameters": {
        "content": "## Deliver\nKeep result rows, shape them and send them to Google Sheets. Nothing is sent when there is nothing new. Header row: scraped_at, category_name, rank, previous_rank, rank_change, new_entry, asin, title, price, currency, rating, reviews_count, product_url.",
        "height": 340,
        "width": 540,
        "color": 7
      }
    },
    {
      "id": "9e454a47-490a-5a0d-9825-e7f823f4fa1f",
      "name": "Every day at 07:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "days",
              "triggerAtHour": 7
            }
          ]
        }
      }
    },
    {
      "id": "4602e76e-9b79-5826-b066-916cc351b0c9",
      "name": "Set search",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        300
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "8540d31a-884b-5cbf-a176-0dd8857c399d",
              "name": "categories",
              "value": "[\"kitchen\"]",
              "type": "array"
            },
            {
              "id": "1f4ae58d-06fc-536a-9331-ed83b07ad350",
              "name": "amazonDomain",
              "value": "com",
              "type": "string"
            },
            {
              "id": "3a365ddc-4484-5fa2-a389-2def53df7246",
              "name": "maxChargeUsd",
              "value": 0.15,
              "type": "number"
            },
            {
              "id": "f63855a4-65e3-5882-baef-edb1f8928461",
              "name": "spreadsheetUrl",
              "value": "https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit",
              "type": "string"
            },
            {
              "id": "416a8e99-8cc9-51ee-b403-d27976329f24",
              "name": "sheetTab",
              "value": "BSR history",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "6bb9df0b-5fca-5bca-b4f3-df334e25751f",
      "name": "Run Amazon Best Sellers Scraper",
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        520,
        300
      ],
      "parameters": {
        "resource": "Actors",
        "operation": "Run actor and get dataset",
        "actorSource": "store",
        "actorId": {
          "__rl": true,
          "mode": "list",
          "value": "NETmBbX7fdm72qFIs",
          "cachedResultName": "Amazon Best Sellers Scraper (aurelix/amazon-best-sellers)",
          "cachedResultUrl": "https://console.apify.com/actors/NETmBbX7fdm72qFIs/input"
        },
        "actorInputMode": "json",
        "customBody": "={{ JSON.stringify({ categories: $json.categories, amazonDomain: $json.amazonDomain, listType: 'bestsellers', maxPages: 2, stateKey: 'n8n-bsr-history-' + $json.categories.join('-') }) }}",
        "memory": 256,
        "timeout": 900,
        "maxTotalChargeUsd": "={{ $json.maxChargeUsd }}"
      }
    },
    {
      "id": "a170ab6e-671d-51c2-bc3a-e5ba9c7862b2",
      "name": "Shape results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        300
      ],
      "parameters": {
        "jsCode": "const rows = $input.all().map(i => i.json).filter(p => p.asin);\nreturn rows.map(p => ({ json: { scraped_at: Array.isArray(p.scraped_at) ? p.scraped_at.join(', ') : (p.scraped_at ?? ''), category_name: Array.isArray(p.category_name) ? p.category_name.join(', ') : (p.category_name ?? ''), rank: Array.isArray(p.rank) ? p.rank.join(', ') : (p.rank ?? ''), previous_rank: Array.isArray(p.previous_rank) ? p.previous_rank.join(', ') : (p.previous_rank ?? ''), rank_change: Array.isArray(p.rank_change) ? p.rank_change.join(', ') : (p.rank_change ?? ''), new_entry: Array.isArray(p.new_entry) ? p.new_entry.join(', ') : (p.new_entry ?? ''), asin: Array.isArray(p.asin) ? p.asin.join(', ') : (p.asin ?? ''), title: Array.isArray(p.title) ? p.title.join(', ') : (p.title ?? ''), price: Array.isArray(p.price) ? p.price.join(', ') : (p.price ?? ''), currency: Array.isArray(p.currency) ? p.currency.join(', ') : (p.currency ?? ''), rating: Array.isArray(p.rating) ? p.rating.join(', ') : (p.rating ?? ''), reviews_count: Array.isArray(p.reviews_count) ? p.reviews_count.join(', ') : (p.reviews_count ?? ''), product_url: Array.isArray(p.product_url) ? p.product_url.join(', ') : (p.product_url ?? '') } }));"
      }
    },
    {
      "id": "dbe1c468-4ac1-54a1-a244-7f6da94dfcb9",
      "name": "Append rows to sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "={{ $('Set search').first().json.spreadsheetUrl }}"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('Set search').first().json.sheetTab }}"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "scraped_at",
              "displayName": "scraped_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "category_name",
              "displayName": "category_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "rank",
              "displayName": "rank",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "previous_rank",
              "displayName": "previous_rank",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "rank_change",
              "displayName": "rank_change",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "new_entry",
              "displayName": "new_entry",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "asin",
              "displayName": "asin",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "title",
              "displayName": "title",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "currency",
              "displayName": "currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "rating",
              "displayName": "rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "reviews_count",
              "displayName": "reviews_count",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "product_url",
              "displayName": "product_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "position": [
        1040,
        300
      ]
    }
  ],
  "connections": {
    "Every day at 07:00": {
      "main": [
        [
          {
            "node": "Set search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set search": {
      "main": [
        [
          {
            "node": "Run Amazon Best Sellers Scraper",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Amazon Best Sellers Scraper": {
      "main": [
        [
          {
            "node": "Shape results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shape results": {
      "main": [
        [
          {
            "node": "Append rows to sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": []
}
