{
  "updatedAt": "2025-03-10T15:33:17.000Z",
  "createdAt": "2024-05-16T08:45:26.144Z",
  "id": "HD6VMHklYPFuzYhT",
  "name": "Sync  Kiotviet vs WP V1- Mecode - Share",
  "description": null,
  "active": false,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "https://id.kiotviet.vn/connect/token",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-type",
              "value": "application/x-www-form-urlencoded"
            }
          ]
        },
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "scopes",
              "value": "PublicApi.Access"
            },
            {
              "name": "grant_type",
              "value": "client_credentials"
            },
            {
              "name": "client_id",
              "value": "={{ $json.client_id }}"
            },
            {
              "name": "client_secret",
              "value": "={{ $json.client_secret }}"
            }
          ]
        },
        "options": {}
      },
      "id": "4dc64aa2-61e9-483a-b87f-d8d255f23379",
      "name": "Lấy access token",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        160,
        -500
      ]
    },
    {
      "parameters": {
        "url": "https://public.kiotapi.com/webhooks",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.configData[0].access_token }}"
            },
            {
              "name": "Retailer",
              "value": "={{ $json.configData[0].retailer }}"
            }
          ]
        },
        "options": {}
      },
      "id": "bc8a1aff-0e6b-4415-9d2b-02484e2025e2",
      "name": "list webhook",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2960,
        -20
      ]
    },
    {
      "parameters": {
        "fields": {
          "values": [
            {
              "name": "client_id"
            },
            {
              "name": "client_secret"
            },
            {
              "name": "access_token_file",
              "stringValue": "/home/node/kiot2wp.json"
            },
            {
              "name": "retailer"
            },
            {
              "name": "page_size",
              "stringValue": "100"
            },
            {
              "name": "url_kiot_webhook_product_change"
            },
            {
              "name": "url_wp"
            },
            {
              "name": "kiot_cat_map_path",
              "stringValue": "/home/node/map_kiot_cats1.json"
            }
          ]
        },
        "include": "selected",
        "options": {}
      },
      "id": "f09f4c36-def3-488b-9470-cbef7d6856bb",
      "name": "configs",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.2,
      "position": [
        -80,
        -420
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 12
            }
          ]
        }
      },
      "id": "1f23bdd5-1827-48b0-b4a9-5be1a3d06758",
      "name": "nữa ngày renew token",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        -300,
        -420
      ]
    },
    {
      "parameters": {
        "operation": "toJson",
        "options": {}
      },
      "id": "08e4873d-b5f8-4167-84b5-7f8d895df05f",
      "name": "convert to file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        680,
        -440
      ]
    },
    {
      "parameters": {
        "operation": "write",
        "fileName": "={{ $('configs').item.json.access_token_file }}",
        "options": {}
      },
      "id": "2a3db432-97ca-4a1b-9c0b-a9a413f631bf",
      "name": "luu file token",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        840,
        -440
      ]
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/kiot2wp.json",
        "options": {}
      },
      "id": "6e50af17-fd8d-4298-84e9-9a550378f6ea",
      "name": "đọc file token",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        -60,
        900
      ]
    },
    {
      "parameters": {
        "operation": "fromJson",
        "destinationKey": "configData",
        "options": {}
      },
      "id": "d8e0cfde-864a-4e28-9e1b-87aa28c02e51",
      "name": "chuyển thành json",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        160,
        900
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "47bd0ea9-8792-4b44-9a7c-50987ff67b6e",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        580,
        500
      ]
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  if(item.json.attributes){\n    item.json.attributes = item.json.attributes.map(x => `${x.attributeName}:${x.attributeValue}` ).join(\"|\");\n  }\n  if(item.json.images){\n    item.json.images = item.json.images.join(\",\");\n  }\n  if(item.json.type){\n    switch(item.json.type){\n      case 1: \n        item.json.type = \"combo\";\n        break;\n      case 2: \n        item.json.type = \"hàng hóa\";\n        break;\n      case 3: \n        item.json.type = \"hàng hóa dịch vụ\";\n        break;\n    }\n  }\n  if(item.json.inventories){\n    let totalStock = 0;\n    let totalOrder = 0;\n    let cost = \"\"\n     item.json.inventories.forEach((iv) => {\n       totalStock  += iv.onHand\n       totalOrder  += iv.reserved\n       if(iv.cost && (!cost || iv.cost > cost)){\n        cost = iv.cost\n       }\n     })\n     \n     item.json.inventories = totalStock\n     item.json.reserved = totalOrder\n     item.json.cost = cost\n  }\n}\n\nreturn $input.all();"
      },
      "id": "567f11b7-cf75-46f9-972c-8acf73723af5",
      "name": "xữ lý biến mãng",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1360,
        780
      ]
    },
    {
      "parameters": {
        "content": "# Hướng dẫn\nFlow đồng bộ sản phẩm và tồn kho từ Kiotviet về WP (Chưa hỗ trợ sản phẩm biến thể)\n\n### 1. Điền thông tin cấu hình ở Node Configs\n### 2. Copy code vào WordPress ở Note 2\n### 3. Chạy Flow 1 để lấy token Kiotviet\n### 4. Chạy Flow 2 để đăng ký Webhook *(nếu muốn Reset Webhook thì chạy Flow 3)*\n### 5. Vào Profile admin Wordpress để tạo Application Password. Và thiết lập quyền các node api Wordpress\n### 6. Chạy Flow 3 để đồng bộ category (chạy lần 2 để đồng bộ phân cấp cha con)\n### 7. Chạy Flow 4 để đồng bộ tất cả sản phẩm\n### 8. Thử update tồn kho để test Webhook ở Flow 5\n\n#### Tác giả: [Đặng Ngọc Bình](https://dangngocbinh.com) - [MeCode](https://mecode.pro) - [Facebook](https://www.facebook.com/dang.ngoc.binh.offical)\n#### [▶️ Đăng ký kênh để nhận những Flow hữu ích khác](https://www.youtube.com/channel/UCBWb-4dT91JS66zU1Oht3WQ)",
        "height": 455.88093959157754,
        "width": 613.7340738267396,
        "color": 3
      },
      "id": "9b556c1b-305c-4e50-b736-daa46418a161",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1140,
        -600
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "kiotsync-product",
        "options": {}
      },
      "id": "1c444b10-b8da-4f6a-a2e1-aa6adbef71d6",
      "name": "products change",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        -320,
        1000
      ],
      "webhookId": "5cf989d3-e229-49cb-bee4-8c4638957e39"
    },
    {
      "parameters": {
        "fieldToSplitOut": "body.Notifications",
        "options": {}
      },
      "id": "e93f2247-4c30-46aa-8ddc-5a2a4334c8c2",
      "name": "Split Out Notifications",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        -40,
        1100
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "Data",
        "options": {}
      },
      "id": "3889e42d-1b55-4b28-8e29-3d4d537a9557",
      "name": "Split Out Data",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        180,
        1100
      ]
    },
    {
      "parameters": {
        "url": "=https://public.kiotapi.com/products/{{ $json.Id }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "retailer",
              "value": "={{ $json.config.retailer }}"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.config.access_token }}"
            }
          ]
        },
        "options": {}
      },
      "id": "eb1b00f2-b586-4821-9b91-b4a7f006aeb4",
      "name": "get detail product",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        780,
        1020
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "multiplex",
        "options": {}
      },
      "id": "b05c0784-c718-4ee6-a346-0d53acccbf28",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        600,
        1020
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "69c57e2e-7f1e-4bfa-a7b1-f95382a7c8af",
              "name": "id",
              "value": "={{ $json.Id }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "selected",
        "includeFields": "Id",
        "options": {}
      },
      "id": "16872694-2b74-4719-becc-c65d84dc55da",
      "name": "keep id only",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        380,
        1100
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "mergeByPosition",
        "options": {}
      },
      "id": "25ee0abc-50c8-4ed5-a53f-7a291fa32adb",
      "name": "Merge2",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        360,
        -440
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "e50d89c6-563a-45db-96bb-7a859b426383",
              "name": "url_wp",
              "value": "={{ $json.url_wp[$json.url_wp.length-1] == \"/\" ? $json.url_wp.slice(0, -1) : $json.url_wp}}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "include": "except",
        "excludeFields": "expires_in,token_type,scope,client_id,client_secret,access_token_file,",
        "options": {}
      },
      "id": "b8e83da2-3958-4d67-a622-b1271c92e097",
      "name": "clean props",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        520,
        -440
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "164148d7-f4cd-47b2-8ba5-249d0a48fa0f",
              "name": "config",
              "value": "={{ $json.configData[0] }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "bd6b7b84-abac-4e61-8cd5-b291e20424ff",
      "name": "extract item 0",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        380,
        900
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "164148d7-f4cd-47b2-8ba5-249d0a48fa0f",
              "name": "config",
              "value": "={{ $json.configData[0] }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "06049950-ba75-474e-ab60-45ee308a5a59",
      "name": "extract item ",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        200,
        500
      ]
    },
    {
      "parameters": {
        "amount": 1
      },
      "id": "0d3edf81-3010-40c9-810c-9cb17341e9eb",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        3040,
        880
      ],
      "webhookId": "88f17460-6635-4c4d-972b-a46fca515661"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://public.kiotapi.com/webhooks",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.configData[0].access_token }}"
            },
            {
              "name": "Retailer",
              "value": "={{ $json.configData[0].retailer }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n\n\"Webhook\": {\n\n\"Type\": \"product.update\", \n\"Url\": \"{{ $json[\"configData\"][0][\"url_kiot_webhook_product_change\"] }}\",\n\"IsActive\": true,\n\"Description\": \"product.update\"\n\n}\n\n}",
        "options": {}
      },
      "id": "19f3a01d-2f8f-4f84-9d62-5308ab9bbfe5",
      "name": "đăng ký webhook - update product",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1680,
        -480
      ]
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/kiot2wp.json",
        "options": {}
      },
      "id": "16107f78-7d03-42c3-9123-9ac3ab42a380",
      "name": "đọc file token3",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        1260,
        -480
      ]
    },
    {
      "parameters": {
        "operation": "fromJson",
        "destinationKey": "configData",
        "options": {}
      },
      "id": "4222a764-4613-441e-a117-501c8a2243fd",
      "name": "chuyển thành json3",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        1460,
        -480
      ]
    },
    {
      "parameters": {
        "operation": "fromJson",
        "destinationKey": "configData",
        "options": {}
      },
      "id": "3c9bfe20-7567-4d6a-bc15-73798840fa75",
      "name": "chuyển thành json4",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2780,
        -20
      ]
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/kiot2wp.json",
        "options": {}
      },
      "id": "4bf1e563-f1db-4b22-86aa-ce53ba8dc89d",
      "name": "đọc file token4",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        2620,
        -20
      ]
    },
    {
      "parameters": {
        "content": "# Flow 6: # Xem Kiotviet Webhooks\n",
        "height": 404.8242863754964,
        "width": 640.530667505157
      },
      "id": "8262f27e-4f11-4fc3-b110-a72526c026aa",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2571.643147203654,
        -100
      ]
    },
    {
      "parameters": {
        "content": "# Flow 2: Đăng Ký Kiotviet Webhook\n",
        "height": 335.4534746760896,
        "width": 747.8916372202596
      },
      "id": "fefbf37d-97cd-4f30-9747-cdaf50aff61b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1220,
        -580
      ]
    },
    {
      "parameters": {
        "content": "# Flow 1: Lấy và Lưu Token & Configs\n",
        "height": 335.4534746760896,
        "width": 1525.8892815076565
      },
      "id": "ea712ea5-8430-4023-98f2-82481effe60a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -380,
        -580
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.wp_url[0] }}/wp-json/wc/v3/products",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "sku",
              "value": "={{ $json.code.join(\",\") }}"
            },
            {
              "name": "per_page",
              "value": "100"
            }
          ]
        },
        "options": {}
      },
      "id": "78fb004d-9cda-4aad-86b8-825f438a111f",
      "name": "query_product_by_skus",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2000,
        640
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.wp_url }}/wp-json/wc/v3/products",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.fullName || $json.name }}"
            },
            {
              "name": "description",
              "value": "={{ $json.description }}"
            },
            {
              "name": "sku",
              "value": "={{ $json.code }}"
            },
            {
              "name": "regular_price",
              "value": "={{ $json.basePrice + \"\" }}"
            },
            {
              "name": "manage_stock",
              "value": "true"
            },
            {
              "name": "stock_quantity",
              "value": "={{ $json.inventories }}"
            },
            {
              "name": "categories",
              "value": "={{  [{id: $json.kiot_cat_maps[$json.categoryId] || 0 }] }}"
            },
            {
              "name": "images",
              "value": "={{ [{src: $json[\"images\"]}] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "c9a8f834-7ddb-4dec-8151-9b93ed61e6d9",
      "name": "tao_sp",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2800,
        880
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      }
    },
    {
      "parameters": {
        "batchSize": 3,
        "options": {}
      },
      "id": "f5f94ac9-f174-431c-8e2b-c04c8efd3d9e",
      "name": "batch",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        1560,
        780
      ]
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "code"
            },
            {
              "fieldToAggregate": "wp_url"
            }
          ]
        },
        "options": {}
      },
      "id": "6258b2af-de60-4f28-86b0-7284ba360988",
      "name": "get_skus",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1780,
        640
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "woo.sku",
              "field2": "code"
            }
          ]
        },
        "joinMode": "enrichInput2",
        "options": {}
      },
      "id": "41d4486f-5ed3-4154-8d20-4af14d1b0b3d",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        2400,
        780
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "35c093dd-7b64-449d-94fe-6bfc31aadfc3",
              "name": "woo",
              "value": "={{ $json }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "3a619742-a796-45d6-98ae-409549723370",
      "name": "put_to_woo_var",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        2220,
        640
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "0f099017-d8e9-41da-a726-025c7b6fd287",
              "leftValue": "={{ $json.woo }}",
              "rightValue": "=",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e4a6d575-55a7-479a-99c3-9b029ec077aa",
      "name": "If_exist_in_wp",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2580,
        780
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "={{ $json.wp_url }}/wp-json/wc/v3/products/{{ $json.woo.id }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "stock_quantity",
              "value": "={{ $json.inventories }}"
            },
            {
              "name": "manage_stock",
              "value": "true"
            },
            {
              "name": "name",
              "value": "={{ $json.fullName || $json.name }}"
            },
            {
              "name": "description",
              "value": "={{ $json.description }}"
            },
            {
              "name": "regular_price",
              "value": "={{ $json.basePrice + \"\" }}"
            },
            {
              "name": "categories",
              "value": "={{  [{id: $json.kiot_cat_maps[$json.categoryId] || 0 }] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "992c17c7-e522-4b08-b94b-ac7cf368f988",
      "name": "update_sp",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2800,
        680
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      }
    },
    {
      "parameters": {
        "url": "https://public.kiotapi.com/products",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "pageSize",
              "value": "100"
            },
            {
              "name": "currentItem",
              "value": "0"
            },
            {
              "name": "includeInventory",
              "value": "1"
            },
            {
              "name": "includePricebook",
              "value": "1"
            },
            {
              "name": "IncludeSerials",
              "value": "1"
            },
            {
              "name": "IncludeBatchExpires",
              "value": "1"
            },
            {
              "name": "includeWarranties",
              "value": "1"
            },
            {
              "name": "includeQuantity",
              "value": "1"
            },
            {
              "name": "includeMaterial",
              "value": "true"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "retailer",
              "value": "={{ $json.config.retailer }}"
            },
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.config.access_token }}"
            }
          ]
        },
        "options": {
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "name": "currentItem",
                    "value": "={{ ( $pageCount || 0) * ( $response.body.pageSize)  }}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ !$response.body.data || $response.body.data.length == 0 }}",
              "requestInterval": 500
            }
          }
        }
      },
      "id": "e552dee5-48f4-4e01-bb35-15c870a8a6b8",
      "name": "get_all_kiot_products",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        400,
        500
      ],
      "notes": "Limit page tam"
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/kiot2wp.json",
        "options": {}
      },
      "id": "38bbb442-c23d-46bd-b074-114c74d0210a",
      "name": "read_configs",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        -140,
        500
      ]
    },
    {
      "parameters": {
        "operation": "fromJson",
        "destinationKey": "configData",
        "options": {}
      },
      "id": "88b60afa-57f7-4183-9424-e1e3aa7575f0",
      "name": "config_bin2json",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        20,
        500
      ]
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/kiot2wp.json",
        "options": {}
      },
      "id": "1f9019ac-e82a-46f6-ae69-b650c444ad4a",
      "name": "đọc file token5",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        2120,
        -480
      ]
    },
    {
      "parameters": {
        "operation": "fromJson",
        "destinationKey": "configData",
        "options": {}
      },
      "id": "2709e3ec-e286-4cd7-b0fa-ee97aaf15df4",
      "name": "chuyển thành json5",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        2320,
        -480
      ]
    },
    {
      "parameters": {
        "content": "# Flow 3: Delete Kiotviet Webhook",
        "height": 335.4534746760896,
        "width": 1130.6681419185006
      },
      "id": "2bb66ac2-42bc-49ae-87a4-1b2ee0f92ede",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2080,
        -580
      ]
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://public.kiotapi.com/webhooks/{{ $json.data[0].id }}/",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $('chuyển thành json5').item.json.configData[0].access_token }}"
            },
            {
              "name": "Retailer",
              "value": "={{ $('chuyển thành json5').item.json.configData[0].retailer }}"
            }
          ]
        },
        "options": {}
      },
      "id": "a57cb7bd-3c6c-430b-a46f-92ea5e0aebc3",
      "name": "delete webhook1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2700,
        -480
      ]
    },
    {
      "parameters": {
        "url": "https://public.kiotapi.com/webhooks",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.configData[0].access_token }}"
            },
            {
              "name": "Retailer",
              "value": "={{ $json.configData[0].retailer }}"
            }
          ]
        },
        "options": {}
      },
      "id": "9e59ff28-4027-45bc-96c5-6ebf05502615",
      "name": "list webhook1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2500,
        -480
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "bfb456b6-37f2-42d5-8846-ef7e796b5f8a",
              "name": "wp_url",
              "value": "={{ $('config_bin2json').item.json.configData[0].url_wp }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "e594ec7a-2731-402c-adec-c9d57972105b",
      "name": "set_wp_url",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        760,
        500
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "bfb456b6-37f2-42d5-8846-ef7e796b5f8a",
              "name": "wp_url",
              "value": "={{ $('chuyển thành json').item.json.configData[0].url_wp }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "984acee7-5f06-48c6-a5b3-b592afe94007",
      "name": "set_wp_url1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        940,
        1020
      ]
    },
    {
      "parameters": {
        "content": "# Flow 4: Đồng bộ tất cả",
        "height": 335.4534746760896,
        "width": 1650.4316708971778
      },
      "id": "55358b15-1d42-4ce8-8a70-b9d4d71f4292",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -400,
        440
      ]
    },
    {
      "parameters": {
        "content": "# Flow 5: Đồng bộ sản phẩm qua Webhook",
        "height": 515.3733943409013,
        "width": 1650.0615201109586
      },
      "id": "fae97502-cae0-4010-8e64-c40a02b8d4bb",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -400,
        820
      ]
    },
    {
      "parameters": {},
      "id": "81955b15-e971-4ccd-a59c-306468aeedd0",
      "name": "When clicking \"Test workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -360,
        520
      ]
    },
    {
      "parameters": {
        "content": "# Flow 3: Đồng bộ categories",
        "height": 404.4453884227203,
        "width": 2920.1981522677406
      },
      "id": "6a75d232-c189-4055-ab9c-dbe57573134f",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -380,
        -100
      ]
    },
    {
      "parameters": {
        "url": "https://public.kiotapi.com/categories",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "pageSize",
              "value": "100"
            },
            {
              "name": "currentItem",
              "value": "1"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.configData[0].access_token }}"
            },
            {
              "name": "Retailer",
              "value": "={{ $json.configData[0].retailer }}"
            }
          ]
        },
        "options": {
          "pagination": {
            "pagination": {
              "parameters": {
                "parameters": [
                  {
                    "name": "currentItem",
                    "value": "={{$pageCount * 100}}"
                  }
                ]
              },
              "paginationCompleteWhen": "other",
              "completeExpression": "={{ !$response || !$response.body || typeof $response.body.data == 'undefined' || $response.body.data.length == 0}}",
              "limitPagesFetched": true
            }
          }
        }
      },
      "id": "f0de9e17-9715-42cd-bbc4-7b62481861be",
      "name": "get_kiot_categories",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        160,
        -40
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "6f0f5c4c-cab0-4497-b715-b2c2b865ebca",
      "name": "split_out_list_cat",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        380,
        -40
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "mergeByPosition",
        "options": {}
      },
      "id": "80757f02-6f62-4802-a481-cdd3844ff905",
      "name": "Merge3",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1480,
        160
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f8e77915-4f8b-4e94-93f5-ba4ab1358c58",
              "name": "kiot_id",
              "value": "={{ $json.categoryId }}",
              "type": "string"
            },
            {
              "id": "281465e3-ad27-4282-b3a9-0eb72c82f686",
              "name": "wc_cat_id",
              "value": "={{ $json.id }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "18091735-44cc-4162-9368-7915a39a2542",
      "name": "map_kiot_wp_product_id",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        2060,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('transform_config_json').item.json.configData[0].url_wp }}/wp-json/wc/v3/products/categories/",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ \n{name: $json[\"categoryName\"],parent: $('set_map_cats').item.json[\"kiot_cat_maps\"][$json.parentId] || 0 }\n}}",
        "options": {}
      },
      "id": "0eb6d655-8078-40cd-a4b4-bb02d9e7c853",
      "name": "create_cat",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1260,
        60
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "content": "## Note 2: Code tích hợp vào WordPress\n*dán vào file function.php của theme hoặc plugin Wp Code:*\n\nadd_action( 'admin_init', 'kiot_map_cats_register_settings' );\nadd_action( 'rest_api_init', 'kiot_map_cats_register_settings' );\n\nfunction kiot_map_cats_register_settings() {\n    register_setting(\n        'kiot_map_cats',\n        'kiot_map_cats',\n        array(\n            'type' => 'object',\n            'show_in_rest' => array(\n                'schema' => array(\n                    'type' => 'object',\n                    'additionalProperties' => array(\n                        'type' => 'string',\n\t\t\t\t\t\t'type' => 'number',\n                    ),\n                ),\n            ),\n            'sanitize_callback' => 'kiot_map_cats_sanitize_callback',\n        )\n    );\n}\n\nfunction kiot_map_cats_sanitize_callback( $value ) {\n \n    $sanitized_value = array();\n\n    if ( is_array( $value ) ) {\n        foreach ( $value as $key => $val ) {\n            $sanitized_value[ sanitize_text_field( $key ) ] = sanitize_text_field( $val );\n        }\n    }\n\n    return $sanitized_value;\n}",
        "height": 300.637321153043,
        "width": 614.1242891353794
      },
      "id": "7e136dfb-64d2-4f75-a077-08c6d9d2575d",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1140,
        -100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('transform_config_json').item.json.configData[0].url_wp }}/wp-json/wp/v2/settings",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {\n\n    \"kiot_map_cats\": $json\n} }}",
        "options": {}
      },
      "id": "3a594b49-8054-454d-ae13-e6c3739e7afe",
      "name": "update_map_cats_options",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        2400,
        0
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "operation": "fromJson",
        "destinationKey": "configData",
        "options": {}
      },
      "id": "526367c6-78b6-41a8-8400-a2a4268ecfad",
      "name": "transform_config_json",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        -140,
        0
      ]
    },
    {
      "parameters": {
        "fileSelector": "=/home/node/kiot2wp.json",
        "options": {}
      },
      "id": "d21f2516-9588-420b-9cb5-a2e101ae2d28",
      "name": "read_config_file",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1,
      "position": [
        -340,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7de53cc5-257b-4809-9d8d-f056f3114b0e",
              "name": "kiot_cat_maps",
              "value": "={{ $json.kiot_map_cats || {} }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "82d48bf4-241a-4785-9c25-a3fbf6c21e2c",
      "name": "set_map_cats",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        380,
        100
      ]
    },
    {
      "parameters": {
        "url": "={{ $('transform_config_json').item.json.configData[0].url_wp }}/wp-json/wp/v2/settings",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "options": {}
      },
      "id": "9976fb8b-6676-424e-977b-990283377162",
      "name": "get_wp_options",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        160,
        100
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "jsCode": "const result = {json:{}, pairedItem: 0}\nfor (const item of $input.all()) {\nresult.json[parseInt(item.json.kiot_id)]= item.json.wc_cat_id\n}\n\nreturn [result]"
      },
      "id": "741abea2-2460-4f30-a8a6-eb5d44d21543",
      "name": "map_cat_id",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2220,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nconst result = []\nfor (const item of $input.all()) {\nObject.keys(item.json.kiot_cat_maps).forEach(\n  (key) => {\n  result.push({kiot_cat_id: parseInt(key), woo_cat_id: item.json.kiot_cat_maps[key]})    \n  }\n)\n\n}\n\nreturn result;"
      },
      "id": "4f0a083f-94e2-4ad5-b601-91abadea2c90",
      "name": "map_to_array",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        100
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {
              "field1": "categoryId",
              "field2": "kiot_cat_id"
            }
          ]
        },
        "joinMode": "enrichInput1",
        "options": {}
      },
      "id": "4e0a57b1-bf05-403d-aee6-1cb6b1c3907c",
      "name": "Merge4",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        760,
        -20
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "ce2de7bb-143b-44f8-8dc0-4a0c7b52e09e",
              "leftValue": "={{ $json.woo_cat_id }}",
              "rightValue": "=",
              "operator": {
                "type": "number",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c211f243-b670-4587-af71-21e22d4ea4bb",
      "name": "If_exist_cat",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        980,
        40
      ]
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "={{ $('transform_config_json').item.json.configData[0].url_wp }}/wp-json/wc/v3/products/categories/{{ $json.woo_cat_id }}",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ \n{name: $json[\"categoryName\"],parent: $('set_map_cats').item.json[\"kiot_cat_maps\"][$json.parentId] || 0 }\n}}",
        "options": {}
      },
      "id": "f07fafba-aeeb-4a57-9ead-a7b796e1cb38",
      "name": "update_cat",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1160,
        -60
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "mergeByPosition",
        "options": {}
      },
      "id": "913c9031-47a7-43c4-b545-4721d33e5958",
      "name": "Merge5",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1740,
        -20
      ]
    },
    {
      "parameters": {},
      "id": "9815367c-4952-43b0-a7cb-6f6da8dc93f5",
      "name": "Merge6",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1880,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.configData[0].url_wp }}/wp-json/wp/v2/settings",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "options": {}
      },
      "id": "72236503-c98a-463c-b6fb-dbb86cac2e56",
      "name": "get_wp_options1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        220,
        660
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7de53cc5-257b-4809-9d8d-f056f3114b0e",
              "name": "kiot_cat_maps",
              "value": "={{ $json.kiot_map_cats || {} }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "430f4022-9132-444b-b641-83769508f2d8",
      "name": "set_map_cats1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        400,
        660
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "multiplex",
        "options": {}
      },
      "id": "234b6708-a3a7-4245-828a-f8646b7ed85a",
      "name": "Merge7",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1020,
        560
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "multiplex",
        "options": {}
      },
      "id": "bfa2ce23-59ec-45a0-a9c8-8ade93ca0984",
      "name": "Merge8",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1160,
        1020
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "7de53cc5-257b-4809-9d8d-f056f3114b0e",
              "name": "kiot_cat_maps",
              "value": "={{ $json.kiot_map_cats || {} }}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "id": "a3ebdf50-bace-4e3d-8c5b-6a5ce06614f7",
      "name": "set_map_cats2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        760,
        820
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.configData[0].url_wp }}/wp-json/wp/v2/settings",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "options": {}
      },
      "id": "212bf932-ea54-4c35-a7a9-2f1ec7c511a1",
      "name": "get_wp_options3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        540,
        800
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "content": "## Roadmaps\n- Hỗ trợ sản phẩm biến thể\n- Update được hình mới \n- Lọc được danh mục cần đồng bộ",
        "width": 612.4364644016573,
        "color": 6
      },
      "id": "493cccaa-b785-4c80-94f0-e96f9eac2e15",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1140,
        240
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "b87e8ae8-3be3-41f7-8760-0704a4d2dc85",
              "leftValue": "={{$json.error}}",
              "rightValue": "=",
              "operator": {
                "type": "object",
                "operation": "exists",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d4cae08a-801b-4f95-81e2-05cf6b004910",
      "name": "If_error",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1300,
        -60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('transform_config_json').item.json.configData[0].url_wp }}/wp-json/wc/v3/products/categories/",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "wordpressApi",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"name\":  \"{{$('If_exist_cat').item.json.categoryName}}\" }\n",
        "options": {}
      },
      "id": "448bc141-bc23-4db5-9834-66b538672ce6",
      "name": "create_cat1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1540,
        -80
      ],
      "credentials": {
        "wordpressApi": {
          "id": "BxuZTQ3qik29yC0E",
          "name": "Binh test site"
        }
      },
      "onError": "continueRegularOutput"
    }
  ],
  "connections": {
    "configs": {
      "main": [
        [
          {
            "node": "Lấy access token",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Lấy access token": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "nữa ngày renew token": {
      "main": [
        [
          {
            "node": "configs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "convert to file": {
      "main": [
        [
          {
            "node": "luu file token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "đọc file token": {
      "main": [
        [
          {
            "node": "chuyển thành json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chuyển thành json": {
      "main": [
        [
          {
            "node": "extract item 0",
            "type": "main",
            "index": 0
          },
          {
            "node": "get_wp_options3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "set_wp_url",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "xữ lý biến mãng": {
      "main": [
        [
          {
            "node": "batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "products change": {
      "main": [
        [
          {
            "node": "Split Out Notifications",
            "type": "main",
            "index": 0
          },
          {
            "node": "đọc file token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Notifications": {
      "main": [
        [
          {
            "node": "Split Out Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Data": {
      "main": [
        [
          {
            "node": "keep id only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "get detail product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "keep id only": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge2": {
      "main": [
        [
          {
            "node": "clean props",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "clean props": {
      "main": [
        [
          {
            "node": "convert to file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extract item 0": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "extract item ": {
      "main": [
        [
          {
            "node": "get_all_kiot_products",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "đọc file token3": {
      "main": [
        [
          {
            "node": "chuyển thành json3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chuyển thành json3": {
      "main": [
        [
          {
            "node": "đăng ký webhook - update product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "đọc file token4": {
      "main": [
        [
          {
            "node": "chuyển thành json4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chuyển thành json4": {
      "main": [
        [
          {
            "node": "list webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "batch": {
      "main": [
        [],
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          },
          {
            "node": "get_skus",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_skus": {
      "main": [
        [
          {
            "node": "query_product_by_skus",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "query_product_by_skus": {
      "main": [
        [
          {
            "node": "put_to_woo_var",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "put_to_woo_var": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "If_exist_in_wp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_exist_in_wp": {
      "main": [
        [
          {
            "node": "update_sp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "tao_sp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "tao_sp": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "update_sp": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_all_kiot_products": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "read_configs": {
      "main": [
        [
          {
            "node": "config_bin2json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "config_bin2json": {
      "main": [
        [
          {
            "node": "extract item ",
            "type": "main",
            "index": 0
          },
          {
            "node": "get_wp_options1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get detail product": {
      "main": [
        [
          {
            "node": "set_wp_url1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "đọc file token5": {
      "main": [
        [
          {
            "node": "chuyển thành json5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "chuyển thành json5": {
      "main": [
        [
          {
            "node": "list webhook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "list webhook1": {
      "main": [
        [
          {
            "node": "delete webhook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_wp_url": {
      "main": [
        [
          {
            "node": "Merge7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_wp_url1": {
      "main": [
        [
          {
            "node": "Merge8",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "When clicking \"Test workflow\"": {
      "main": [
        [
          {
            "node": "read_configs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_kiot_categories": {
      "main": [
        [
          {
            "node": "split_out_list_cat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "split_out_list_cat": {
      "main": [
        [
          {
            "node": "Merge4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge3": {
      "main": [
        [
          {
            "node": "Merge6",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "map_kiot_wp_product_id": {
      "main": [
        [
          {
            "node": "map_cat_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "create_cat": {
      "main": [
        [
          {
            "node": "Merge3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "transform_config_json": {
      "main": [
        [
          {
            "node": "get_kiot_categories",
            "type": "main",
            "index": 0
          },
          {
            "node": "get_wp_options",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "read_config_file": {
      "main": [
        [
          {
            "node": "transform_config_json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_wp_options": {
      "main": [
        [
          {
            "node": "set_map_cats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "map_cat_id": {
      "main": [
        [
          {
            "node": "update_map_cats_options",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_map_cats": {
      "main": [
        [
          {
            "node": "map_to_array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "map_to_array": {
      "main": [
        [
          {
            "node": "Merge4",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge4": {
      "main": [
        [
          {
            "node": "If_exist_cat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_exist_cat": {
      "main": [
        [
          {
            "node": "update_cat",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge5",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "create_cat",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge3",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "update_cat": {
      "main": [
        [
          {
            "node": "If_error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge5": {
      "main": [
        [
          {
            "node": "Merge6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge6": {
      "main": [
        [
          {
            "node": "map_kiot_wp_product_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_wp_options1": {
      "main": [
        [
          {
            "node": "set_map_cats1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge7": {
      "main": [
        [
          {
            "node": "xữ lý biến mãng",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_map_cats1": {
      "main": [
        [
          {
            "node": "Merge7",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge8": {
      "main": [
        [
          {
            "node": "xữ lý biến mãng",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get_wp_options3": {
      "main": [
        [
          {
            "node": "set_map_cats2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "set_map_cats2": {
      "main": [
        [
          {
            "node": "Merge8",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_error": {
      "main": [
        [
          {
            "node": "create_cat1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "create_cat1": {
      "main": [
        [
          {
            "node": "Merge5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": {
    "node:nữa ngày renew token": {
      "recurrencyRules": [
        20
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "pinData": {},
  "versionId": "8dc7852f-91f7-4bb4-b377-bd9061a962ea",
  "activeVersionId": null,
  "versionCounter": 1,
  "triggerCount": 2,
  "shared": [
    {
      "updatedAt": "2024-05-16T08:45:26.153Z",
      "createdAt": "2024-05-16T08:45:26.153Z",
      "role": "workflow:owner",
      "workflowId": "HD6VMHklYPFuzYhT",
      "projectId": "Nlp7kXCVcAfb0cmG",
      "project": {
        "updatedAt": "2024-07-25T03:06:26.102Z",
        "createdAt": "2024-07-25T03:06:26.102Z",
        "id": "Nlp7kXCVcAfb0cmG",
        "name": "Bình Đặng <dangngocbinh.dnb@gmail.com>",
        "type": "personal",
        "icon": null,
        "description": null,
        "creatorId": "92f1ca82-c19e-4a7d-8458-93b65f67f4c7"
      }
    }
  ],
  "tags": [
    {
      "updatedAt": "2024-05-16T03:58:58.232Z",
      "createdAt": "2024-05-16T03:58:58.232Z",
      "id": "8twcNf1L6fQLYE9I",
      "name": "mecode"
    },
    {
      "updatedAt": "2024-10-04T03:03:40.628Z",
      "createdAt": "2024-10-04T03:03:40.628Z",
      "id": "MW10UcI4NI01thiG",
      "name": "share"
    },
    {
      "updatedAt": "2024-05-16T03:59:00.479Z",
      "createdAt": "2024-05-16T03:59:00.479Z",
      "id": "ZzqMLRDiDsHzihck",
      "name": "kiotviet"
    }
  ],
  "activeVersion": null
}