n8n-backup/workflows/Billbee Aufträge -> Data Wa...

769 lines
19 KiB
JSON
Raw Normal View History

{
"active": false,
"connections": {
"HTTP Request1": {
"main": [
[
{
"node": "Split Response Into Orders",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "HTTP Request1",
"type": "main",
"index": 0
}
]
]
},
"Split Response Into Orders": {
"main": [
[
{
"node": "Upsert Customer",
"type": "main",
"index": 0
},
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"Postgres": {
"main": [
[
{
"node": "Merge1",
"type": "main",
"index": 0
}
]
]
},
"Crypto": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Upsert Customer": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"Merge": {
"main": [
[
{
"node": "Crypto",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Postgres",
"type": "main",
"index": 0
},
{
"node": "Merge1",
"type": "main",
"index": 1
}
]
]
},
"Merge1": {
"main": [
[
{
"node": "Item Lists",
"type": "main",
"index": 0
}
]
]
},
"Item Lists": {
"main": [
[
{
"node": "IF1",
"type": "main",
"index": 0
}
]
]
},
"Code1": {
"main": [
[
{
"node": "Postgres2",
"type": "main",
"index": 0
}
]
]
},
"Postgres2": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"IF1": {
"main": [
[
{
"node": "Code2",
"type": "main",
"index": 0
}
],
[
{
"node": "Code1",
"type": "main",
"index": 0
}
]
]
},
"Code2": {
"main": [
[
{
"node": "Baserow",
"type": "main",
"index": 0
},
{
"node": "Merge2",
"type": "main",
"index": 1
}
]
]
},
"Baserow": {
"main": [
[
{
"node": "Merge2",
"type": "main",
"index": 0
}
]
]
}
},
"createdAt": "2023-12-11T17:25:14.909Z",
"id": "55eZFqIMkqfMEtaC",
"meta": null,
"name": "Billbee Aufträge -> Data Warehouse",
"nodes": [
{
"parameters": {
"url": "https://app.billbee.io/api/v1/orders",
"authentication": "genericCredentialType",
"genericAuthType": "httpBasicAuth",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "minOrderDate",
"value": "={{ $today.minus(1 $day) }}"
},
{
"name": "pageSize",
"value": "250"
}
]
},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-Billbee-Api-Key",
"value": "2855BE2C-1D67-4AB0-9DEB-3073E6D27B1C"
}
]
},
"options": {}
},
"id": "34781fe0-a66e-43a6-a616-45a1ad27f2e8",
"name": "HTTP Request1",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
-260,
-1340
],
"credentials": {
"httpBasicAuth": {
"id": "xANPcw3p1Nh0wF9J",
"name": "Billbee Basic"
}
}
},
{
"parameters": {
"rule": {
"interval": [
{
"triggerAtMinute": 5
}
]
}
},
"id": "28e8e58e-aea3-4c88-b174-7f4a51c425bd",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.1,
"position": [
-520,
-1340
]
},
{
"parameters": {
"schema": {
"__rl": true,
"mode": "list",
"value": "public"
},
"table": {
"__rl": true,
"value": "fact_order_details",
"mode": "list",
"cachedResultName": "fact_order_details"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"product_id": "={{ $json.Product.EAN }}",
"quantity": "={{ $json.Quantity }}",
"price_each": "={{ $json.TotalPrice / $json.Quantity}}",
"order_detail_id": 0,
"order_id": 0
},
"matchingColumns": [],
"schema": [
{
"id": "order_detail_id",
"displayName": "order_detail_id",
"required": false,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": true
},
{
"id": "order_id",
"displayName": "order_id",
"required": true,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": true
},
{
"id": "product_id",
"displayName": "product_id",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true
},
{
"id": "quantity",
"displayName": "quantity",
"required": true,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": true
},
{
"id": "price_each",
"displayName": "price_each",
"required": true,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": true
}
]
},
"options": {}
},
"id": "dab64316-4942-4207-b75a-dcd78704ab05",
"name": "Postgres1",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.3,
"position": [
2600,
-1580
],
"credentials": {
"postgres": {
"id": "JW5wwsSY4obQbCBb",
"name": "Postgres - warehouse"
}
}
},
{
"parameters": {
"operation": "upsert",
"schema": {
"__rl": true,
"mode": "list",
"value": "public"
},
"table": {
"__rl": true,
"value": "dim_customers",
"mode": "list",
"cachedResultName": "dim_customers"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"customer_id": "={{ $json.Customer.Number }}",
"customer_country": "={{ $json.ShippingAddress.CountryISO2 }}"
},
"matchingColumns": [
"customer_id"
],
"schema": [
{
"id": "customer_id",
"displayName": "customer_id",
"required": false,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": true,
"removed": false
},
{
"id": "customer_country",
"displayName": "customer_country",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": false
}
]
},
"options": {}
},
"id": "6bd22bb9-e978-436e-bfa0-5f7579dec8d0",
"name": "Upsert Customer",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.3,
"position": [
300,
-1480
],
"credentials": {
"postgres": {
"id": "JW5wwsSY4obQbCBb",
"name": "Postgres - warehouse"
}
}
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json }} {{ $json.product_ean }}",
"operation": "notEqual",
"value2": "={{ null }}"
}
]
}
},
"id": "7991fd99-8f2d-4911-bc42-98b1c78269b3",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2540,
-1280
]
},
{
"parameters": {
"fieldToSplitOut": "Data",
"options": {}
},
"id": "f951938c-ca90-4f33-9dce-099084407196",
"name": "Split Response Into Orders",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 3,
"position": [
40,
-1480
]
},
{
"parameters": {
"operation": "upsert",
"schema": {
"__rl": true,
"value": "public",
"mode": "list",
"cachedResultName": "public"
},
"table": {
"__rl": true,
"value": "dim_orders",
"mode": "list",
"cachedResultName": "dim_orders"
},
"columns": {
"mappingMode": "defineBelow",
"value": {
"order_id": "={{ $json.order_hash }}",
"platform_id": "={{ $json.platform }}",
"customer_id": "={{ $json.Customer.Number }}",
"order_date": "={{ $json.CreatedAt.toDate().format(\"yyyyMMdd\") }}",
"order_ref": "={{ $json.OrderNumber }}"
},
"matchingColumns": [
"order_id"
],
"schema": [
{
"id": "order_ref",
"displayName": "order_ref",
"required": false,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": false
},
{
"id": "order_date",
"displayName": "order_date",
"required": true,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": false
},
{
"id": "customer_id",
"displayName": "customer_id",
"required": true,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": false
},
{
"id": "platform_id",
"displayName": "platform_id",
"required": false,
"defaultMatch": false,
"display": true,
"type": "number",
"canBeUsedToMatch": false
},
{
"id": "order_id",
"displayName": "order_id",
"required": true,
"defaultMatch": false,
"display": true,
"type": "string",
"canBeUsedToMatch": true,
"removed": false
}
]
},
"options": {}
},
"id": "716963ce-227c-470b-83d5-85c4af9442f3",
"name": "Postgres",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.3,
"position": [
1120,
-1320
],
"credentials": {
"postgres": {
"id": "JW5wwsSY4obQbCBb",
"name": "Postgres - warehouse"
}
}
},
{
"parameters": {
"value": "={{ $json.OrderNumber.concat($json.CreatedAt.toDate().format(\"yyyy-MM-d\")) }}",
"dataPropertyName": "=order_hash"
},
"id": "67fd82c6-055a-41d7-bc5e-ca727b0f9777",
"name": "Crypto",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [
700,
-1320
]
},
{
"parameters": {
"mode": "chooseBranch",
"output": "input2"
},
"id": "8490a7f7-6f11-487b-8f81-4c97f56c638b",
"name": "Merge",
"type": "n8n-nodes-base.merge",
"typeVersion": 2.1,
"position": [
500,
-1320
]
},
{
"parameters": {
"language": "python",
"pythonCode": "# Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor item in _input.all():\n\tmatch item.json.Seller.BillbeeShopName:\n\t\tcase 'eBay':\n item.json.platform = 12\n\t\tcase 'lana-kk':\n item.json.platform = 1\n\t\tcase 'Amazon':\n item.json.platform = 2\n\t\tcase 'Weltkarten24':\n item.json.platform = 3\n\t\tcase 'KAUFLAND':\n item.json.platform = 5\n\t\tcase 'Wayfair':\n item.json.platform = 4\n\t\tcase 'Böttcher AG':\n item.json.platform = 7\n\t\tcase 'Juramondo':\n item.json.platform = 9\n\t\tcase 'wild.lanakk.com':\n item.json.platform = 8\n\t\tcase 'Etsy':\n item.json.platform = 10\n\t\tcase 'Otto':\n item.json.platform = 6\n\t\tcase 'weltkarte-kinder':\n item.json.platform = 11\n\t\tcase _:\n item.json.platform = 1\nreturn _input.all()\n"
},
"id": "2006b054-3147-4f8a-b8d1-6ce19554dfde",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
-1320
]
},
{
"parameters": {
"mode": "chooseBranch",
"output": "input2"
},
"id": "5d30f116-d392-4a34-9977-c9cb1bcaae07",
"name": "Merge1",
"type": "n8n-nodes-base.merge",
"typeVersion": 2.1,
"position": [
1300,
-1100
]
},
{
"parameters": {
"fieldToSplitOut": "OrderItems",
"include": "selectedOtherFields",
"fieldsToInclude": "order_hash",
"options": {}
},
"id": "dc3a5418-691f-42a9-b09f-bb4c9d0e2155",
"name": "Item Lists",
"type": "n8n-nodes-base.itemLists",
"typeVersion": 3,
"position": [
1520,
-1100
]
},
{
"parameters": {
"language": "python",
"pythonCode": "# Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor item in _input.all():\n if item.json.OrderItems.Product.EAN is None:\n print(\"hoho\")\n item.json.OrderItems.Product.EAN = \"9999999999999\"\n item.json.OrderItems.Product.order_detail_sku = item.json.OrderItems.Product.SKU\nreturn _input.all()\n"
},
"id": "2b2f4265-e3af-444e-81d6-61c976ead182",
"name": "Code1",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
2040,
-1120
]
},
{
"parameters": {
"operation": "select",
"schema": {
"__rl": true,
"mode": "list",
"value": "public"
},
"table": {
"__rl": true,
"value": "dim_products",
"mode": "list",
"cachedResultName": "dim_products"
},
"limit": 1,
"where": {
"values": [
{
"column": "product_ean",
"value": "={{ $json.OrderItems.Product.EAN }}"
}
]
},
"options": {}
},
"id": "54832aff-c8aa-476e-89ce-762f1d037ed3",
"name": "Postgres2",
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.3,
"position": [
2180,
-1100
],
"alwaysOutputData": true,
"credentials": {
"postgres": {
"id": "JW5wwsSY4obQbCBb",
"name": "Postgres - warehouse"
}
}
},
{
"parameters": {
"databaseId": 104,
"tableId": 526,
"limit": 1,
"additionalOptions": {
"filters": {
"fields": [
{
"field": 4229,
"value": "={{ $json.OrderItems.Product.SKU }}"
}
]
}
}
},
"id": "6cbb5ce8-550a-4b3c-b87f-3f1d1a3a7f02",
"name": "Baserow",
"type": "n8n-nodes-base.baserow",
"typeVersion": 1,
"position": [
2140,
-1700
],
"alwaysOutputData": true,
"credentials": {
"baserowApi": {
"id": "j10WQMd09rnsjW3T",
"name": "Baserow account"
}
}
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json.OrderItems.Product.EAN }}",
"value2": "={{ null }}"
},
{
"value1": "={{ $json.OrderItems.Product.SKU }}",
"operation": "notEqual",
"value2": "={{ null }}"
}
]
}
},
"id": "8f0d7af7-8f64-45c9-8bf7-9c13b7f71991",
"name": "IF1",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1720,
-1280
]
},
{
"parameters": {
"language": "python",
"pythonCode": "# Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor item in _input.all():\n product = item.json.OrderItems.Product\n if product and product.get('SKU'):\n print('hey')\n # Correct old SKU schema\n product.SKU = product.SKU.replace('worldmap','wm')\n product.SKU = product.SKU.replace('weltkarte','wk')\n # Correct very old Amazon SKUs\n product.SKU = product.SKU.replace('kork_M1','-de-kork-l_120x80-1-S')\n product.SKU = product.SKU.replace('kork_S','-de-kork-l_100x70-1-S')\nreturn _input.all()"
},
"id": "d49cb597-20e6-4580-8a14-6c876eefa24a",
"name": "Code2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1860,
-1520
]
},
{
"parameters": {
"mode": "combine",
"mergeByFields": {
"values": [
{
"field1": "['SKU (Text)']",
"field2": "OrderItems.Product.SKU"
}
]
},
"joinMode": "enrichInput2",
"options": {}
},
"id": "bd3d3873-ac13-4d0d-97d3-97a7feb867b6",
"name": "Merge2",
"type": "n8n-nodes-base.merge",
"typeVersion": 2.1,
"position": [
2180,
-1360
]
}
],
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"tags": [],
"triggerCount": 0,
"updatedAt": "2023-12-18T19:09:43.000Z",
"versionId": "b828beea-9c8a-43fd-97b6-f3ad61c8fb22"
}