n8n-backup/workflows/Shopify <--> Mautic.json

656 lines
16 KiB
JSON

{
"active": true,
"connections": {
"Shopify Trigger": {
"main": [
[
{
"node": "Search Contact by EMail",
"type": "main",
"index": 0
}
]
]
},
"Move Binary Data": {
"main": [
[
{
"node": "Hash incoming data",
"type": "main",
"index": 0
}
]
]
},
"Search Contact by EMail": {
"main": [
[
{
"node": "Contact found?",
"type": "main",
"index": 0
}
]
]
},
"Contact found?": {
"main": [
[
{
"node": "Accepts Marketing?",
"type": "main",
"index": 0
}
],
[
{
"node": "Contact accepts marketing?",
"type": "main",
"index": 0
}
]
]
},
"Contact accepts marketing?": {
"main": [
[
{
"node": "Create new Contact",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Create new Contact": {
"main": [
[
{
"node": "Add Contact to Segment",
"type": "main",
"index": 0
}
]
]
},
"Accepts Marketing?": {
"main": [
[
{
"node": "Add Contact to Segment",
"type": "main",
"index": 0
}
],
[
{
"node": "Remove from Segment",
"type": "main",
"index": 0
}
]
]
},
"Webhook Call": {
"main": [
[
{
"node": "Move Binary Data",
"type": "main",
"index": 0
}
]
]
},
"Hash incoming data": {
"main": [
[
{
"node": "Compare Hashes",
"type": "main",
"index": 0
}
]
]
},
"Compare Hashes": {
"main": [
[
{
"node": "Get customer from Shopify",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing1",
"type": "main",
"index": 0
}
]
]
},
"Get customer from Shopify": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Mautic - Accepts Marketing?": {
"main": [
[
{
"node": "Marketing Consent - subscribed",
"type": "main",
"index": 0
}
],
[
{
"node": "Marketing Consent - unsubscribed",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "Mautic - Accepts Marketing?",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing2",
"type": "main",
"index": 0
}
]
]
}
},
"createdAt": "2023-08-25T09:30:15.825Z",
"id": "4",
"meta": {
"templateCredsSetupCompleted": true
},
"name": "Shopify <--> Mautic",
"nodes": [
{
"parameters": {},
"id": "614139b6-28fa-4983-9732-9cfaad82067a",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
400,
660
]
},
{
"parameters": {
"authentication": "accessToken",
"topic": "customers/update"
},
"id": "b20ef5e3-b002-4d29-bacf-cb731237803b",
"name": "Shopify Trigger",
"type": "n8n-nodes-base.shopifyTrigger",
"typeVersion": 1,
"position": [
-680,
280
],
"webhookId": "ebce58fc-45cf-4c1c-8427-3ffbaccdb440",
"credentials": {
"shopifyAccessTokenApi": {
"id": "11",
"name": "Shopify Access Token account"
}
}
},
{
"parameters": {
"setAllData": false,
"options": {}
},
"id": "2677101f-c550-4748-afef-e41fe1af0604",
"name": "Move Binary Data",
"type": "n8n-nodes-base.moveBinaryData",
"typeVersion": 1,
"position": [
-380,
1140
]
},
{
"parameters": {},
"id": "6cb7bd1f-939d-43af-966e-171a1ba3d7da",
"name": "No Operation, do nothing1",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
400,
1300
]
},
{
"parameters": {
"authentication": "oAuth2",
"operation": "getAll",
"limit": 1,
"options": {
"search": "={{ $json.email }}"
}
},
"id": "2ab62e7d-70aa-444e-a4a3-d5b6f4db23e4",
"name": "Search Contact by EMail",
"type": "n8n-nodes-base.mautic",
"typeVersion": 1,
"position": [
-400,
280
],
"alwaysOutputData": true,
"credentials": {
"mauticOAuth2Api": {
"id": "6",
"name": "Mautic account"
}
}
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.id }}",
"operation": "isNotEmpty"
}
]
}
},
"id": "2e6cebc8-94ce-473c-9248-f5cc359ee300",
"name": "Contact found?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
-140,
280
],
"alwaysOutputData": false
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $('Shopify Trigger').item.json[\"accepts_marketing\"] }}",
"value2": "={{ true }}"
}
]
}
},
"id": "f6faee14-d93d-4b85-b8fa-9f4d8c127594",
"name": "Contact accepts marketing?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
120,
560
]
},
{
"parameters": {
"authentication": "oAuth2",
"email": "={{ $('Shopify Trigger').item.json[\"email\"] }}",
"firstName": "={{ $('Shopify Trigger').item.json[\"first_name\"] }}",
"lastName": "={{ $('Shopify Trigger').item.json[\"last_name\"] }}",
"company": "=",
"additionalFields": {},
"options": {}
},
"id": "cb999a33-6849-4e36-8141-b5e80c19b175",
"name": "Create new Contact",
"type": "n8n-nodes-base.mautic",
"typeVersion": 1,
"position": [
400,
460
],
"credentials": {
"mauticOAuth2Api": {
"id": "6",
"name": "Mautic account"
}
}
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $node[\"Shopify Trigger\"].json[\"accepts_marketing\"] }}",
"value2": "={{ true }}"
}
]
}
},
"id": "b83cfae2-25dc-4ed6-8133-73ee7bb94b29",
"name": "Accepts Marketing?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
400,
260
]
},
{
"parameters": {
"authentication": "oAuth2",
"resource": "contactSegment",
"contactId": "={{ $json.id }}",
"segmentId": 1
},
"id": "a1f319db-2e89-42d7-a018-a5f008e918dc",
"name": "Add Contact to Segment",
"type": "n8n-nodes-base.mautic",
"typeVersion": 1,
"position": [
780,
160
],
"credentials": {
"mauticOAuth2Api": {
"id": "6",
"name": "Mautic account"
}
}
},
{
"parameters": {
"authentication": "oAuth2",
"resource": "contactSegment",
"operation": "remove",
"contactId": "={{ $json.id }}",
"segmentId": 1
},
"id": "830fd450-d149-47b1-afd0-5999ecdcdf54",
"name": "Remove from Segment",
"type": "n8n-nodes-base.mautic",
"typeVersion": 1,
"position": [
780,
400
],
"credentials": {
"mauticOAuth2Api": {
"id": "6",
"name": "Mautic account"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "c83eb6ce-40dd-418c-952a-ed62a051a00b",
"options": {
"rawBody": true
}
},
"id": "98653876-b909-4416-a8ee-aa5857078b48",
"name": "Webhook Call",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
-660,
1140
],
"webhookId": "c83eb6ce-40dd-418c-952a-ed62a051a00b"
},
{
"parameters": {
"action": "hmac",
"type": "SHA256",
"value": "={{ $json.data }}",
"dataPropertyName": "=key",
"secret": "0a9dcfe4f362625efc5a38bc709598c61869552fcfc1aceb8fc08edad8dd3825",
"encoding": "base64"
},
"id": "2c64dae7-5409-4767-92ab-43239bb038f0",
"name": "Hash incoming data",
"type": "n8n-nodes-base.crypto",
"typeVersion": 1,
"position": [
-140,
1140
]
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json[\"headers\"][\"webhook-signature\"] }}",
"value2": "={{ $json.key }}"
}
]
}
},
"id": "d16fae8c-6b13-42cb-831b-437c41919b1b",
"name": "Compare Hashes",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
100,
1140
]
},
{
"parameters": {
"authentication": "headerAuth",
"endpoint": "https://lana-kk.myshopify.com/admin/api/2023-04/graphql.json",
"query": "={\n customers(first: 1, query: \"email:'{{ $json[\"body\"][\"mautic.lead_channel_subscription_changed\"][0][\"contact\"][\"fields\"][\"core\"][\"email\"][\"value\"] }}'\" ) {\n edges {\n node {\n id\n email\n marketingOptInLevel\n }\n }\n }\n}"
},
"id": "08ea065c-cc8d-4020-89c0-0aa35d99a373",
"name": "Get customer from Shopify",
"type": "n8n-nodes-base.graphql",
"typeVersion": 1,
"position": [
400,
1000
],
"credentials": {
"httpHeaderAuth": {
"id": "5",
"name": "lanakk.com - Shopify"
}
}
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "= {{ $node[\"Webhook Call\"].json.body[\"mautic.lead_channel_subscription_changed\"][0].new_status }}",
"operation": "regex",
"value2": "=contactable"
}
]
},
"combineOperation": "any"
},
"id": "107bae94-57b1-4991-a8eb-41e85e5f85af",
"name": "Mautic - Accepts Marketing?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
940,
860
]
},
{
"parameters": {
"authentication": "headerAuth",
"endpoint": "https://lana-kk.myshopify.com/admin/api/2023-04/graphql.json",
"requestFormat": "json",
"query": "=mutation customerEmailMarketingConsentUpdate($input: CustomerEmailMarketingConsentUpdateInput!) {\n customerEmailMarketingConsentUpdate(input: $input) {\n customer {\n id\n }\n userErrors {\n field\n message\n }\n }\n}",
"variables": "={ \"input\": { \"customerId\": \"{{ $node[\"Get customer from Shopify\"].json[\"data\"][\"customers\"][\"edges\"][0][\"node\"][\"id\"] }}\", \"emailMarketingConsent\": { \"consentUpdatedAt\": \"{{ $now }}\", \"marketingOptInLevel\": \"SINGLE_OPT_IN\", \"marketingState\": \"SUBSCRIBED\" } }}"
},
"id": "52d46a11-f459-449c-b93e-2890a94b1e65",
"name": "Marketing Consent - subscribed",
"type": "n8n-nodes-base.graphql",
"typeVersion": 1,
"position": [
1280,
720
],
"credentials": {
"httpHeaderAuth": {
"id": "5",
"name": "lanakk.com - Shopify"
}
}
},
{
"parameters": {
"authentication": "headerAuth",
"endpoint": "https://lana-kk.myshopify.com/admin/api/2023-04/graphql.json",
"requestFormat": "json",
"query": "=mutation customerEmailMarketingConsentUpdate($input: CustomerEmailMarketingConsentUpdateInput!) {\n customerEmailMarketingConsentUpdate(input: $input) {\n customer {\n id\n }\n userErrors {\n field\n message\n }\n }\n}",
"variables": "={ \"input\": { \"customerId\": \"{{ $node[\"Get customer from Shopify\"].json[\"data\"][\"customers\"][\"edges\"][0][\"node\"][\"id\"] }}\", \"emailMarketingConsent\": { \"consentUpdatedAt\": \"{{ $now }}\", \"marketingOptInLevel\": \"SINGLE_OPT_IN\", \"marketingState\": \"UNSUBSCRIBED\" } }}"
},
"id": "4815d1b0-2455-4bb0-8dd3-717b216e60a1",
"name": "Marketing Consent - unsubscribed",
"type": "n8n-nodes-base.graphql",
"typeVersion": 1,
"position": [
1280,
1000
],
"credentials": {
"httpHeaderAuth": {
"id": "5",
"name": "lanakk.com - Shopify"
}
}
},
{
"parameters": {
"content": "## Shopify \nThe n8n Shopify node cannot get customer marketing consent, so we get this from the Shopify GraphQL API",
"width": 279.1188177339898
},
"id": "9004b0a4-4946-4a64-9a1c-c1b960333c1b",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
100,
860
]
},
{
"parameters": {
"content": "## Webhook Validation\nWe use the same key shared with Mautic to hash the incoming request. If the computed hash is identical to the one delivered the request is valid and can be processed",
"width": 580.807881773399
},
"id": "13640a02-f955-400d-9476-605977ec9d99",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
-380,
1300
]
},
{
"parameters": {
"content": "## Shopify \nThe n8n Shopify node cannot set customer marketing consent, so we send a mutation to the Shopify GraphQL API",
"height": 383.7477832512317,
"width": 279.1188177339898
},
"id": "f6150b76-e147-4a7b-a797-055f66bda89e",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
1480,
720
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "4d2f02ab-f5e3-437d-8a35-f301888a8597",
"leftValue": "={{ $json.data.customers.edges }}",
"rightValue": 0,
"operator": {
"type": "array",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {
"looseTypeValidation": false
}
},
"id": "52707587-103d-4d86-876d-aa96ace2d202",
"name": "If",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
660,
1000
]
},
{
"parameters": {},
"id": "ad9ce920-2b6e-4b41-b56f-516025964e4e",
"name": "No Operation, do nothing2",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
940,
1160
]
}
],
"pinData": {},
"settings": {},
"staticData": {
"node:Shopify Trigger": {
"webhookId": 1374787961097
}
},
"tags": [],
"triggerCount": 2,
"updatedAt": "2024-02-14T08:13:18.000Z",
"versionId": "18c368e9-f44a-406e-920b-938c4f6d0cdd"
}