{
  "id": "XgxCTBp0eakz6BDy",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Retail - Transfer Inventory Updates Across Systems",
  "tags": [],
  "nodes": [
    {
      "id": "91ded471-7fd7-439a-b549-5fbb62fd5838",
      "name": "Inventory Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -128,
        16
      ],
      "parameters": {
        "path": "inventory-update",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "e7ec7048-62c0-4433-bc3f-e302562eebe9",
      "name": "Normalize Inventory Data",
      "type": "n8n-nodes-base.set",
      "position": [
        144,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "364a3173-056e-4712-aed4-766eade86360",
              "name": "body.id",
              "type": "number",
              "value": "={{ $json.body.id }}"
            },
            {
              "id": "71175c5a-035a-439a-812b-dfc267e33584",
              "name": "body.sku",
              "type": "string",
              "value": "={{ $json.body.sku }}"
            },
            {
              "id": "74535433-e371-419e-84ac-22fe92d440d5",
              "name": "body.stock_quantity",
              "type": "number",
              "value": "={{ $json.body.stock_quantity }}"
            },
            {
              "id": "4e647d91-a664-416f-8f56-b955974c392b",
              "name": "body.date_modified",
              "type": "string",
              "value": "={{ $json.body.date_modified }}"
            },
            {
              "id": "34ed830b-fcea-486e-8a7d-b8aab7cb6cae",
              "name": "body.manage_stock",
              "type": "boolean",
              "value": "={{ $json.body.manage_stock }}"
            },
            {
              "id": "9cc391b4-8796-45a8-95e6-e952faceb6ea",
              "name": "body.type",
              "type": "string",
              "value": "={{ $json.body.type }}"
            },
            {
              "id": "87fea61e-913b-4637-bbf2-b0012770d4f1",
              "name": "body.status",
              "type": "string",
              "value": "={{ $json.body.status }}"
            },
            {
              "id": "abe70acf-3c68-462a-aca1-46973912be54",
              "name": "body.source",
              "type": "string",
              "value": "={{ $json.body.source }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e684f603-500c-4306-845b-3e99d8c4d4fa",
      "name": "Check Sync Origin",
      "type": "n8n-nodes-base.if",
      "position": [
        432,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "669342e7-f4c7-43eb-88b4-0bcf050603d6",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.body.source }}",
              "rightValue": "\"secondary-system\""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "3e2a34ff-a113-4bf8-9d89-d74a8e644480",
      "name": "Prepare Inventory Payload",
      "type": "n8n-nodes-base.code",
      "position": [
        656,
        -32
      ],
      "parameters": {
        "jsCode": "return [{\n  json: {\n    id: $('Normalize Inventory Data').first().json.body.id,\n    sku: $('Normalize Inventory Data').first().json.body.sku,\n    qty: Number($('Normalize Inventory Data').first().json.body.stock_quantity),\n    dateModified: $('Normalize Inventory Data').first().json.body.date_modified,\n    type: $('Normalize Inventory Data').first().json.body.type,\n    origin: $('Normalize Inventory Data').first().json.body.source,\n    status: $('Normalize Inventory Data').first().json.body.status\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "31d2b2ea-bd0a-46ab-b32a-28bfd0dd9130",
      "name": "Send Inventory To Secondary API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        -32
      ],
      "parameters": {
        "method": "POST",
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "id",
              "value": "={{ $json.id }}"
            },
            {
              "name": "sku",
              "value": "={{ $json.sku }}"
            },
            {
              "name": "qty",
              "value": "={{ $json.qty }}"
            },
            {
              "name": "dateModified",
              "value": "={{ $json.dateModified }}"
            },
            {
              "name": "type",
              "value": "={{ $json.type }}"
            },
            {
              "name": "origin",
              "value": "={{ $json.origin }}"
            },
            {
              "name": "status",
              "value": "={{ $json.status }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "58f465b6-99fd-4319-85d9-50b04a1b7e76",
      "name": "Log Inventory Sync To Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1264,
        -32
      ],
      "parameters": {
        "columns": {
          "value": {
            "Id": "={{ $('Prepare Inventory Payload').item.json.id }}",
            "SKU": "={{ $('Prepare Inventory Payload').item.json.sku }}",
            "Type": "={{ $('Prepare Inventory Payload').item.json.type }}",
            "Quantity": "={{ $('Prepare Inventory Payload').item.json.qty }}",
            "Sync Status": "={{ $('Prepare Inventory Payload').item.json.status }}",
            "Date Modified": "={{ $('Prepare Inventory Payload').item.json.status }}",
            "Source System": "={{ $('Prepare Inventory Payload').item.json.origin }}"
          },
          "schema": [
            {
              "id": "Id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "SKU",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "SKU",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Quantity",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Source System",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Source System",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Sync Status",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Sync Status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Type",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Date Modified",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Date Modified",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tZp-X-3ZLwkj53h7BKhM5DbZKf3zVOtg-kcOIjmrA4w/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1tZp-X-3ZLwkj53h7BKhM5DbZKf3zVOtg-kcOIjmrA4w",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tZp-X-3ZLwkj53h7BKhM5DbZKf3zVOtg-kcOIjmrA4w/edit?usp=drivesdk",
          "cachedResultName": "Inventory_Sync_Log"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "e51d34f3-4758-485a-b499-ff0ae01bfe2b",
      "name": "Inventory Sync Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        -240
      ],
      "parameters": {
        "color": null,
        "width": 656,
        "height": 496,
        "content": "## Retail \u2013 Transfer Inventory Updates Across Systems\n\n### Purpose\nAutomatically synchronize inventory quantity updates between systems such as online stores, POS, ERP or warehouse platforms. This workflow ensures that stock changes remain consistent across systems and are logged for tracking and auditing.\n\n### How it works\nThe workflow listens for inventory update events via a webhook. Incoming data is normalized to extract key fields such as product ID, SKU, quantity, source system and modification timestamp. A validation step checks the origin of the update to prevent circular sync loops. Valid updates are transformed into a clean API-ready payload and sent to a secondary system. After a successful API call, the update is logged into Google Sheets for visibility and reference.\n\n### Setup steps\n1. Configure the Webhook URL in your source system to send inventory updates.  \n2. Ensure SKU, stock quantity, source and date modified fields are included in the payload.  \n3. Update the HTTP Request node with your secondary system API endpoint.  \n4. Connect Google Sheets and prepare the sheet with required headers.  \n5. Activate the workflow to start processing inventory updates.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "168e11af-13ca-4ce8-996d-4e83c5d60e01",
      "name": "Trigger & Data Preparation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 544,
        "height": 368,
        "content": "## Trigger & Data Preparation\n\nDetects inventory update events from the source system and prepares a standardized data structure by extracting essential fields such as SKU, quantity, source system and modification timestamp for downstream processing.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2296361e-34b6-4c05-bfc9-568a631ecfae",
      "name": "Inventory Sync",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        384,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 368,
        "content": "## Inventory Sync\n\nValidates the origin of the inventory update to prevent circular sync loops, prepares a clean and API-ready payload and sends the inventory update to the secondary system for synchronization.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "7144a960-d2a9-455d-97ca-dfdc0e315772",
      "name": "Logging",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1072,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 464,
        "height": 368,
        "content": "## Logging\n\nRecords inventory sync details such as SKU, quantity, source system, status into Google Sheets for auditing, tracking and operational visibility."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4ad6fe44-b3ca-4ed0-a1eb-97d1c3ef7c72",
  "connections": {
    "Check Sync Origin": {
      "main": [
        [
          {
            "node": "Prepare Inventory Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Inventory Webhook": {
      "main": [
        [
          {
            "node": "Normalize Inventory Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Inventory Data": {
      "main": [
        [
          {
            "node": "Check Sync Origin",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Inventory Payload": {
      "main": [
        [
          {
            "node": "Send Inventory To Secondary API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Inventory To Secondary API": {
      "main": [
        [
          {
            "node": "Log Inventory Sync To Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}