Price Sync

Off-the-shelf Shopify plugins only support simple rules (+10%, round up). I needed per-SKU custom pricing with manual overrides across marketplaces.
{
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -96,
        -1648
      ],
      "id": "046b9e29-a46e-4c56-a2db-a63c184a9921",
      "name": "When clicking ‘Execute workflow’"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 3
          },
          "conditions": [
            {
              "id": "fd944256-d5b4-4e7a-8c03-2276fb0639e4",
              "leftValue": "={{ $json.SKU }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "693fc331-1da7-44a7-9e42-08a509384ba7",
              "leftValue": "={{ $json.Price }}",
              "rightValue": "^(?!0+(\\.0+)?$)\\d+(\\.\\d+)?$",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.3,
      "position": [
        320,
        -1104
      ],
      "id": "220a751a-fbe8-4f7f-a644-1479110f03c0",
      "name": "Filter",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "bd429d4f-b259-4a88-b4fb-1d53553ca6dc",
              "leftValue": "={{ $json.Title }}",
              "rightValue": "Sync",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        528,
        -1328
      ],
      "id": "0169eefd-3be5-4e61-80fa-9d51b6926139",
      "name": "Check for Pause"
    },
    {
      "parameters": {
        "jsCode": "const safeRound = (val, decimals = 2) => {\n  const num = parseFloat(val);\n  return isNaN(num) ? \"0.00\" : num.toFixed(decimals);\n};\n\nconst priceFields = [\n  \"Price\",\n  \"Amazon Price (variant.metafields.custom.amazon_price)\",\n  \"eBay Price (variant.metafields.custom.ebay_price)\",\n];\n\nreturn $input.all().map(item => {\n  priceFields.forEach(field => {\n    item.json[field] = safeRound(item.json[field]);\n  });\n  return item;\n});\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        96,
        -1104
      ],
      "id": "570d3787-d88b-49f4-8fe8-1273a9838a49",
      "name": "Sanitize",
      "executeOnce": false
    },
    {
      "parameters": {
        "compare": "selectedFields",
        "fieldsToCompare": "handle",
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        528,
        -864
      ],
      "id": "8eb2e6e6-3c59-4b57-bc7e-5c6e1a1bc3c2",
      "name": "Remove Duplicates",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "endpoint": "https://p1kbkx-4k.myshopify.com/admin/api/2025-01/graphql.json",
        "query": "query getVariantId($handle: String!) {\n  productByHandle(handle: $handle) {\n    id\n    variants(first: 250) {\n      edges {\n        node {\n          id\n          sku\n        }\n      }\n    }\n  }\n}",
        "variables": "={\n  \"handle\": \"{{ $json.handle }}\"\n}"
      },
      "type": "n8n-nodes-base.graphql",
      "typeVersion": 1.1,
      "position": [
        752,
        -864
      ],
      "id": "bbfc6bd1-5425-42d5-b418-b2dcc4602aa1",
      "name": "Get VariantIds",
      "credentials": {
        "httpHeaderAuth": {
          "id": "LjoCkMxtBmt8kzzv",
          "name": "Shopify n8n custom app"
        }
      }
    },
    {
      "parameters": {
        "fieldToSplitOut": "data.productByHandle.variants.edges",
        "include": "selectedOtherFields",
        "fieldsToInclude": "data.productByHandle.id",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        912,
        -864
      ],
      "id": "bb9f186e-4889-4f4e-b358-38a91df1cff3",
      "name": "Split Out",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "aY3YXuu95CR0Vp0i",
          "mode": "list",
          "cachedResultName": "cardmuseum-products",
          "cachedResultUrl": "/projects/oIullNh5DjDV0FR1/datatables/aY3YXuu95CR0Vp0i"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": []
        },
        "returnAll": true
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        528,
        -1104
      ],
      "id": "9a6d4135-1c09-4410-b303-606e5b0ac534",
      "name": "Products from DB",
      "alwaysOutputData": true,
      "executeOnce": true
    },
    {
      "parameters": {
        "jsCode": "const allProductsFromSheet = $('Filter').all();\nconst allProductsFromDatabase = $('Products from DB').all();\n\nconst dbMap = Object.fromEntries(\n  allProductsFromDatabase.map(item => [item.json.sku, item.json.price])\n);\n\nreturn allProductsFromSheet\n  .filter(item => {\n    const sku = item.json.SKU;\n    const sheetPrice = item.json.Price;\n    return !(sku in dbMap) || dbMap[sku] !== sheetPrice;\n  })\n  .map(item => {\n    item.json._status = item.json.SKU in dbMap ? 'updated' : 'new';\n    return item;\n  });"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        752,
        -1104
      ],
      "id": "02f77765-93b7-4cfd-89ed-9579d66e5e4e",
      "name": "New Or Changed",
      "executeOnce": true
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json._status }}",
                    "rightValue": "new",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "775a9462-c312-4352-8f5d-e2c1881a39b0"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "new"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "3833c935-d885-4269-9409-35f81b563899",
                    "leftValue": "={{ $json._status }}",
                    "rightValue": "updated",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "updated"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        96,
        -784
      ],
      "id": "d7e51d05-4a72-4928-be43-49ab397bf23e",
      "name": "Switch"
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "endpoint": "https://p1kbkx-4k.myshopify.com/admin/api/2025-01/graphql.json",
        "query": "mutation updateVariant($productId: ID!, $variants: [ProductVariantsBulkInput!]!) {\n  productVariantsBulkUpdate(productId: $productId, variants: $variants) {\n    productVariants {\n      id\n      sku\n      price\n    }\n    userErrors {\n      field\n      message\n    }\n  }\n}",
        "variables": "={\n  \"productId\": \"{{ $json.productId }}\",\n  \"variants\": {{ JSON.stringify($json.variants) }}\n}"
      },
      "type": "n8n-nodes-base.graphql",
      "typeVersion": 1.1,
      "position": [
        96,
        -400
      ],
      "id": "97fa17f8-7a99-4085-8972-065f7e705751",
      "name": "Shopify Update",
      "credentials": {
        "httpHeaderAuth": {
          "id": "LjoCkMxtBmt8kzzv",
          "name": "Shopify n8n custom app"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\n// Group variants by productId\nconst productMap = {};\n\nfor (const item of items) {\n  const productId = item.json.productId; // from your lookup step\n  \n  if (!productMap[productId]) {\n    productMap[productId] = [];\n  }\n\n  productMap[productId].push({\n    id: item.json.variantId,\n    price: item.json.price,\n    metafields: [\n      {\n        namespace: \"custom\",\n        key: \"amazon_price\",\n        value: item.json.amazon_price\n      },\n      {\n        namespace: \"custom\",\n        key: \"ebay_price\",\n        value: item.json.ebay_price\n      }\n    ]\n  });\n}\n\n// One item per product → one mutation call each\nreturn Object.entries(productMap).map(([productId, variants]) => ({\n  json: {\n    productId,\n    variants\n  }\n}));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -96,
        -400
      ],
      "id": "942e27f5-fe49-429b-b7d4-55d454472d9f",
      "name": "Shopify Dataset"
    },
    {
      "parameters": {
        "jsCode": "return $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1088,
        -624
      ],
      "id": "41466ce8-483c-4fd3-a412-1a5dd9b0945a",
      "name": "Collect"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.amazon.com/auth/o2/token",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpCustomAuth",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "refresh_token"
            },
            {
              "name": "refresh_token",
              "value": ""
            },
            {
              "name": "client_id",
              "value": ""
            },
            {
              "name": "client_secret",
              "value": ""
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        96,
        -224
      ],
      "id": "c31fda61-27e8-4c30-af65-b1d5485756d9",
      "name": "Amazon Token",
      "credentials": {
        "httpHeaderAuth": {
          "id": "12xdruvcvgQoWqT0",
          "name": "Sumtracker"
        },
        "httpCustomAuth": {
          "id": "Mm01CvFLiSn6HH6L",
          "name": "Amazon Marketplace LWS Auth"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://sellingpartnerapi-eu.amazon.com/feeds/2021-06-30/documents",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-amz-access-token",
              "value": "={{ $('Amazon Token').item.json.access_token }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "contentType",
              "value": "application/json; charset=UTF-8"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        320,
        -224
      ],
      "id": "f0724351-6c67-4ae2-975d-47d476d5d2a2",
      "name": "Amazon Create Feed"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://sellingpartnerapi-eu.amazon.com/feeds/2021-06-30/feeds",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-amz-access-token",
              "value": "={{ $('Amazon Token').item.json.access_token }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"feedType\": \"JSON_LISTINGS_FEED\",\n  \"inputFeedDocumentId\": \"{{ $('Amazon Create Feed').item.json.feedDocumentId }}\",\n  \"marketplaceIds\": [\"A1PA6795UKMFR9\"]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        704,
        -224
      ],
      "id": "14e7ddeb-89d3-4c89-a5d6-ed310ce7231e",
      "name": "Amazon Submit Feed"
    },
    {
      "parameters": {
        "method": "PUT",
        "url": "={{ $json.url }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json; charset=UTF-8"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($('Amazon Dataset').item.json.feedPayload) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        512,
        -224
      ],
      "id": "113ca9dd-ffd8-43e7-b6aa-cd07f605f18e",
      "name": "Amazon Put Feed"
    },
    {
      "parameters": {
        "url": "=https://sellingpartnerapi-eu.amazon.com/feeds/2021-06-30/feeds/{{ $json.feedId }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "x-amz-access-token",
              "value": "={{ $('Amazon Token').item.json.access_token }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        64,
        32
      ],
      "id": "3e35312b-0abb-4bad-94fa-5c52c39c7689",
      "name": "Amazon Check Feed"
    },
    {
      "parameters": {
        "amount": 1,
        "unit": "minutes"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -96,
        32
      ],
      "id": "9c6c8436-8ccc-46d6-94ff-5dd8e6b5e457",
      "name": "Wait",
      "webhookId": "710a97a7-bbe3-4184-b46d-e302e81bc49a"
    },
    {
      "parameters": {
        "errorMessage": "=Amazon Feed processingStatus {{ $('Amazon Check Feed').item.json.processingStatus }}"
      },
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        528,
        16
      ],
      "id": "22535806-7532-43ea-8293-e3e80b44e5ba",
      "name": "Stop and Error"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.processingStatus }}",
                    "rightValue": "DONE",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "fa6dd8ff-acf8-4d5c-a8ba-9b8d253edfde"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "DONE"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "88657e38-3fff-4b08-be87-20b1ed6252c1",
                    "leftValue": "={{ $json.processingStatus }}",
                    "rightValue": "CANCELLED",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "CANCELLED"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "7cb788b2-326f-4a11-bee2-108f394dec6a",
                    "leftValue": "={{ $json.processingStatus }}",
                    "rightValue": "FATAL",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "FATAL"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "bd6eba8f-f3ef-406b-b264-dc1bea942469",
                    "leftValue": "={{ $json.processingStatus }}",
                    "rightValue": "IN_PROGRESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "IN_PROGRESS"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "8d3bee68-f0a7-4d93-b1ad-2d882ee572ad",
                    "leftValue": "{{ $json.processingStatus }}",
                    "rightValue": "IN_QUEUE",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "IN_QUEUE"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        256,
        -16
      ],
      "id": "a2805bd4-7e3c-4716-8c7c-efc2ea6ab08b",
      "name": "Check Response Switch"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 3
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -96,
        -1472
      ],
      "id": "db33047a-b5f7-4105-928f-8bb0c46a1b89",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyX",
              "value": 5,
              "unit": "minutes"
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "value": "1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E",
          "mode": "list",
          "cachedResultName": "Product Information Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 561040518,
          "mode": "list",
          "cachedResultName": "Products",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E/edit#gid=561040518"
        },
        "options": {
          "columnsToWatch": [
            "Price",
            "Amazon Price (variant.metafields.custom.amazon_price)",
            "eBay Price (variant.metafields.custom.ebay_price)"
          ]
        }
      },
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        -96,
        -1312
      ],
      "id": "93acddb7-bcc2-4ea5-a903-417522c81c1f",
      "name": "Google Sheets Trigger",
      "executeOnce": true,
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "id": "6hvz26BNNiuNXhdn",
          "name": "Google Sheets Trigger account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "51d39540-88b0-4949-a8d6-53f0523cf9de",
              "leftValue": "={{ $input.all().length }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        96,
        -1312
      ],
      "id": "e171b534-9039-4c96-b2f0-1fb05020b324",
      "name": "If",
      "executeOnce": true
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E",
          "mode": "list",
          "cachedResultName": "Product Information Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 561040518,
          "mode": "list",
          "cachedResultName": "Products",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E/edit#gid=561040518"
        },
        "filtersUI": {
          "values": []
        },
        "options": {
          "dataLocationOnSheet": {
            "values": {
              "rangeDefinition": "specifyRangeA1",
              "range": "A:AD"
            }
          }
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        752,
        -1344
      ],
      "id": "691b5945-34d6-491d-bd64-8fea0335a3ca",
      "name": "Get All Rows",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "uL8j4dE3HU7eS4JB",
          "name": "LF Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E",
          "mode": "list",
          "cachedResultName": "Product Information Master",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 561040518,
          "mode": "list",
          "cachedResultName": "Products",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1GG8rV-kpYtW5sR3WStC1lKkAS4X5LRdW249F4sQpz0E/edit#gid=561040518"
        },
        "filtersUI": {
          "values": []
        },
        "options": {
          "dataLocationOnSheet": {
            "values": {
              "rangeDefinition": "specifyRangeA1",
              "range": "A1:A2"
            }
          }
        }
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        304,
        -1328
      ],
      "id": "27b3fd23-5cc2-4cf8-b954-9899ceaa4b93",
      "name": "Get Sync Field",
      "executeOnce": true,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "uL8j4dE3HU7eS4JB",
          "name": "LF Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\nconst SELLER_ID = 'A2AD2HJJ66EI93';\nconst MARKETPLACE_ID = 'A1PA6795UKMFR9';\n\nconst messages = items.filter((item) => item.json.asin).map((item, index) => ({\n  messageId: index + 1,\n  sku: item.json.sku,\n  operationType: 'PATCH',\n  productType: 'PRODUCT',\n  patches: [\n    {\n      op: 'replace',\n      path: '/attributes/purchasable_offer',\n      value: [\n        {\n          audience: 'ALL',\n          currency: 'EUR',\n          our_price: [\n            {\n              schedule: [{\n                value_with_tax: item.json.amazon_price\n              }]\n            }\n          ]\n        }\n      ]\n    }\n  ]\n}));\n\nconst feedPayload = {\n  header: {\n    sellerId: SELLER_ID,\n    version: '2.0',\n    issueLocale: 'de_DE',\n  },\n  messages\n};\n\nif (messages.length) {\n  return [{ json: { feedPayload } }];\n}\n\nreturn null"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -96,
        -224
      ],
      "id": "ff7ec91f-5f10-4c03-9eba-3c8eff4a2da5",
      "name": "Amazon Dataset"
    },
    {
      "parameters": {
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "value": "aY3YXuu95CR0Vp0i",
          "mode": "list",
          "cachedResultName": "cardmuseum-products",
          "cachedResultUrl": "/projects/oIullNh5DjDV0FR1/datatables/aY3YXuu95CR0Vp0i"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "sku",
              "keyValue": "={{ $json.SKU }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "price": "={{ $json.Price }}",
            "amazon_price": "={{ $json['Amazon Price (variant.metafields.custom.amazon_price)'] }}",
            "ebay_price": "={{ $json['eBay Price (variant.metafields.custom.ebay_price)'] }}",
            "sku": "={{ $json.SKU }}",
            "handle": "={{ $json.Handle }}",
            "asin": "={{ $json[\"Variant ASIN (variant.metafields.custom.amazon_variant_asin)\"] }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "amazon_price",
              "displayName": "amazon_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "ebay_price",
              "displayName": "ebay_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "sku",
              "displayName": "sku",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "handle",
              "displayName": "handle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "variantId",
              "displayName": "variantId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "productId",
              "displayName": "productId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "asin",
              "displayName": "asin",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        320,
        -864
      ],
      "id": "caa115f1-7afe-477b-b346-d553af77951c",
      "name": "Insert Products"
    },
    {
      "parameters": {
        "operation": "upsert",
        "dataTableId": {
          "__rl": true,
          "value": "aY3YXuu95CR0Vp0i",
          "mode": "list",
          "cachedResultName": "cardmuseum-products",
          "cachedResultUrl": "/projects/oIullNh5DjDV0FR1/datatables/aY3YXuu95CR0Vp0i"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "sku",
              "keyValue": "={{ $json.SKU }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "price": "={{ $json.Price }}",
            "amazon_price": "={{ $json['Amazon Price (variant.metafields.custom.amazon_price)'] }}",
            "ebay_price": "={{ $json['eBay Price (variant.metafields.custom.ebay_price)'] }}",
            "sku": "={{ $json.SKU }}",
            "handle": "={{ $json.Handle }}",
            "asin": "={{ $json[\"Variant ASIN (variant.metafields.custom.amazon_variant_asin)\"] }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "amazon_price",
              "displayName": "amazon_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "ebay_price",
              "displayName": "ebay_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "sku",
              "displayName": "sku",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "handle",
              "displayName": "handle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "variantId",
              "displayName": "variantId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "productId",
              "displayName": "productId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "asin",
              "displayName": "asin",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        320,
        -624
      ],
      "id": "694c94e2-f27f-4ac0-87cb-70d06cb6a8d9",
      "name": "Update Products"
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "value": "aY3YXuu95CR0Vp0i",
          "mode": "list",
          "cachedResultName": "cardmuseum-products",
          "cachedResultUrl": "/projects/oIullNh5DjDV0FR1/datatables/aY3YXuu95CR0Vp0i"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "sku",
              "keyValue": "={{ $json['data.productByHandle.variants.edges'].node.sku }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "variantId": "={{ $json['data.productByHandle.variants.edges'].node.id }}",
            "productId": "={{ $json['data.productByHandle.id'] }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "amazon_price",
              "displayName": "amazon_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "ebay_price",
              "displayName": "ebay_price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "sku",
              "displayName": "sku",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "handle",
              "displayName": "handle",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "variantId",
              "displayName": "variantId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "productId",
              "displayName": "productId",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1088,
        -864
      ],
      "id": "8dc64840-4946-4ee3-bcb5-efd810587bba",
      "name": "Add Variant Id",
      "alwaysOutputData": true
    }
  ],
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Get Sync Field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Products from DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for Pause": {
      "main": [
        [
          {
            "node": "Get All Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sanitize": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Duplicates": {
      "main": [
        [
          {
            "node": "Get VariantIds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get VariantIds": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Add Variant Id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Products from DB": {
      "main": [
        [
          {
            "node": "New Or Changed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New Or Changed": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Insert Products",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Products",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shopify Dataset": {
      "main": [
        [
          {
            "node": "Shopify Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect": {
      "main": [
        [
          {
            "node": "Shopify Dataset",
            "type": "main",
            "index": 0
          },
          {
            "node": "Amazon Dataset",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Token": {
      "main": [
        [
          {
            "node": "Amazon Create Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Create Feed": {
      "main": [
        [
          {
            "node": "Amazon Put Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Submit Feed": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Put Feed": {
      "main": [
        [
          {
            "node": "Amazon Submit Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Check Feed": {
      "main": [
        [
          {
            "node": "Check Response Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Amazon Check Feed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Response Switch": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Sync Field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Get Sync Field",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get All Rows": {
      "main": [
        [
          {
            "node": "Sanitize",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Sync Field": {
      "main": [
        [
          {
            "node": "Check for Pause",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amazon Dataset": {
      "main": [
        [
          {
            "node": "Amazon Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Products": {
      "main": [
        [
          {
            "node": "Remove Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Products": {
      "main": [
        [
          {
            "node": "Collect",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Variant Id": {
      "main": [
        [
          {
            "node": "Collect",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "627a52eb1cafccb20a270f896af13c9d987f22f1b3523531f639a14cda474a89"
  }
}