{"id": "fGtaDiSrkFG9MaOC", "name": "My workflow 2", "nodes": [{"id": "1562791c-33a9-425c-a774-32e328bd4715", "name": "Token Request", "type": "n8n-nodes-base.httpRequest", "notes": "Get the token from Dartagnan that expires after 60 minutes", "position": [60, 200], "parameters": {"url": "https://app.dartagnan.io/oauth/v2/token", "method": "POST", "options": {"redirect": {"redirect": {}}}, "sendBody": true, "bodyParameters": {"parameters": [{"name": "client_id", "value": "={{ $('Assign Credentials').item.json.client_id }}"}, {"name": "client_secret", "value": "={{ $('Assign Credentials').item.json.client_secret }}"}, {"name": "grant_type", "value": "client_credentials"}]}}, "typeVersion": 4.2}, {"id": "2d81394c-9898-419a-a832-339e66d56a29", "name": "Assign Credentials", "type": "n8n-nodes-base.set", "position": [-400, 300], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "debe5309-40f6-411d-8c4d-3b282cf1bba9", "name": "client_id", "type": "string", "value": "Enter your Dartagnan client_id"}, {"id": "6028c0c0-a701-449e-952e-46895280e4ef", "name": "client_secret", "type": "string", "value": "Enter your Dartagnan client_secret"}, {"id": "7e82aa01-18ff-4b76-802b-cc8cae987614", "name": "instance_url", "type": "string", "value": "Enter your Braze instance_url like https://rest.fra-02.braze.eu for example"}, {"id": "a3c641d7-fdbd-4e96-a845-e2c5aad93398", "name": "api_key", "type": "string", "value": "Enter your Braze API key"}]}}, "typeVersion": 3.4}, {"id": "b80a8eda-bbf6-4560-8665-5128a97db217", "name": "Dartagnan Project list", "type": "n8n-nodes-base.httpRequest", "position": [360, 200], "parameters": {"url": "https://app.dartagnan.io/api/public/projects", "options": {"redirect": {"redirect": {}}}, "sendHeaders": true, "headerParameters": {"parameters": [{"name": "Authorization", "value": "=Bearer {{ $json.access_token }}"}]}}, "typeVersion": 4.2}, {"id": "909eb4f9-d67e-4f5e-bdb6-67ef2da813a4", "name": "Create email template", "type": "n8n-nodes-base.httpRequest", "position": [2420, 400], "parameters": {"url": "=https://{{ $item(\"0\").$node[\"Assign Credentials\"].json[\"instance_url\"] }}/templates/email/create", "method": "POST", "options": {"redirect": {"redirect": {}}}, "jsonBody": "={\n \"template_name\": \"{{ $('Filter Braze vs Dartagnan').item.json.unified_name }}\",\n \"subject\": \"Subject Line\",\n \"body\": {{ $json.encoded_html }},\n \"plaintext_body\":{{ $json.encoded_plaintext_body }}\n}", "sendBody": true, "sendHeaders": true, "specifyBody": "json", "headerParameters": {"parameters": [{"name": "Authorization", "value": "=Bearer {{ $item(\"0\").$node[\"Assign Credentials\"].json[\"api_key\"] }}"}, {"name": "Content-Type", "value": "application/json"}]}}, "typeVersion": 4.2}, {"id": "0820220a-5ea6-42eb-bfd2-f697dcf37a8a", "name": "List Available Email Template Braze", "type": "n8n-nodes-base.httpRequest", "position": [60, 420], "parameters": {"url": "=https://{{ $('Assign Credentials').item.json.instance_url }}/templates/email/list ", "options": {"redirect": {"redirect": {}}}, "sendQuery": true, "sendHeaders": true, "queryParameters": {"parameters": [{}]}, "headerParameters": {"parameters": [{"name": "Authorization", "value": "=Bearer {{ $('Assign Credentials').item.json.api_key }}"}]}}, "executeOnce": false, "typeVersion": 4.2}, {"id": "dcfec31d-c42c-4545-91a0-3b2e3350d375", "name": "Filtered Project Campaign", "type": "n8n-nodes-base.httpRequest", "notes": "POC Avec la derniere valeur avant iteration sur une boucle for dans la v2", "position": [640, 200], "parameters": {"url": "=https://app.dartagnan.io/api/public/projects/{{ $json.id }}", "options": {"redirect": {"redirect": {}}}, "sendHeaders": true, "headerParameters": {"parameters": [{"name": "Authorization", "value": "=Bearer {{ $('Token Request').item.json.access_token }}"}]}}, "typeVersion": 4.2}, {"id": "1aba6e4c-d3b0-49f8-8bcb-bece8cce4b4d", "name": "Filtering Dartagnan Campaigns", "type": "n8n-nodes-base.set", "position": [840, 200], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "e82823f9-e094-48e6-9d10-8d10c126ffa8", "name": "id", "type": "string", "value": "={{ $json.campaigns[0].id }}"}, {"id": "31ddce2b-7366-448c-a68f-bfea4dcb057b", "name": "campaign_name", "type": "string", "value": "={{ $json.campaigns[0].name }}"}, {"id": "0eb93a91-fbd5-45f9-b47c-89340f716909", "name": "=unified_name", "type": "string", "value": "={{ $json.campaigns[0].name }}-{{ $json.campaigns[0].id }}"}, {"id": "e784ad19-301f-45f7-b90b-27bcce06b6dc", "name": "creation_date", "type": "string", "value": "={{ $json.campaigns[0].created }}"}, {"id": "8e99802a-1342-4482-afc7-fbe22df6cffc", "name": "update_date", "type": "string", "value": "={{ $json.campaigns[0].updated }}"}, {"id": "f5814048-5cb6-465f-a95a-c56913c9ed2d", "name": "created_by", "type": "string", "value": "={{ $json.campaigns[0].createdBy.firstname }} {{ $json.campaigns[0].createdBy.lastname }}"}, {"id": "19442a15-bf61-47e1-987f-709de70f8f08", "name": "modified_by", "type": "string", "value": "={{ $json.campaigns[0].updatedBy.firstname }} {{ $json.campaigns[0].updatedBy.lastname }}"}, {"id": "b75db148-0006-4327-a418-49347da5b970", "name": "access_token", "type": "string", "value": "={{ $('Token Request').item.json.access_token }}"}]}}, "typeVersion": 3.4}, {"id": "ee26ca98-2c42-4e69-ab34-cc2d737c22f8", "name": "Split Out", "type": "n8n-nodes-base.splitOut", "position": [360, 420], "parameters": {"options": {}, "fieldToSplitOut": "templates"}, "typeVersion": 1}, {"id": "08d8372f-38cb-4722-95aa-c89bfcc36dff", "name": "Filtering Braze Email Template", "type": "n8n-nodes-base.set", "position": [800, 420], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "920fd95b-bf48-494d-9d55-d5d961fd459f", "name": "braze_template_name", "type": "string", "value": "={{ $json.template_name }}"}, {"id": "8425c3c2-07c3-4c3d-a58e-e8d1460fea9c", "name": "email_template_id", "type": "string", "value": "={{ $json.email_template_id }}"}, {"id": "1944b20a-147b-4b4d-9558-f2927de9b2f2", "name": "created_at", "type": "string", "value": "={{ $json.created_at }}"}, {"id": "850a4a0a-d27b-43cb-a8a3-2d810a5fdc13", "name": "updated_at", "type": "string", "value": "={{ $json.updated_at }}"}]}}, "typeVersion": 3.4}, {"id": "3e07fa37-8afd-4d88-85a3-53a4f000f898", "name": "Not existing In Braze", "type": "n8n-nodes-base.merge", "position": [1160, 420], "parameters": {"mode": "combine", "options": {}, "advanced": true, "joinMode": "keepNonMatches", "mergeByFields": {"values": [{"field1": "unified_name", "field2": "braze_template_name"}]}}, "typeVersion": 3}, {"id": "210a9d44-f58f-4788-89bd-934dfc0fca41", "name": "Existing In Braze", "type": "n8n-nodes-base.merge", "position": [1140, 200], "parameters": {"mode": "combine", "options": {}, "advanced": true, "mergeByFields": {"values": [{"field1": "unified_name", "field2": "braze_template_name"}]}}, "typeVersion": 3}, {"id": "59f8270b-b988-452b-aaf0-0e7b35490449", "name": "Dartagnan HTML & MEDIA To Update", "type": "n8n-nodes-base.httpRequest", "position": [1740, 180], "parameters": {"url": "=https://app.dartagnan.io/api/public/campaigns/{{ $json.id }}", "options": {"redirect": {"redirect": {}}}, "sendQuery": true, "sendHeaders": true, "queryParameters": {"parameters": [{}]}, "headerParameters": {"parameters": [{"name": "Authorization", "value": "=Bearer {{ $('Token Request').item.json.access_token }}"}]}}, "typeVersion": 4.2}, {"id": "04b26314-cb00-4a90-a7fe-019936a5ba2a", "name": "Encode Content To Update", "type": "n8n-nodes-base.set", "position": [2180, 180], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "fb308822-842f-4559-b5c9-96853c79e00e", "name": "encoded_html", "type": "string", "value": "={{JSON.stringify( $json.html )}} "}, {"id": "390b747b-967d-45f4-9faf-3aaed605d769", "name": "encoded_plaintext_body", "type": "string", "value": "={{JSON.stringify($json.text)}} "}]}}, "typeVersion": 3.4}, {"id": "1455fd2e-85ee-4844-8c4b-755870dc9cee", "name": "Dartagnan HTML & MEDIA Campagne to Create", "type": "n8n-nodes-base.httpRequest", "position": [1760, 400], "parameters": {"url": "=https://app.dartagnan.io/api/public/campaigns/{{ $json.id }}", "options": {"redirect": {"redirect": {}}}, "sendQuery": true, "sendHeaders": true, "queryParameters": {"parameters": [{}]}, "headerParameters": {"parameters": [{"name": "Authorization", "value": "=Bearer {{ $('Token Request').item.json.access_token }}"}]}}, "typeVersion": 4.2}, {"id": "214d8b4b-c512-4d1f-8115-8491f6fc9272", "name": "Encode Content to Create", "type": "n8n-nodes-base.set", "position": [2200, 400], "parameters": {"options": {}, "assignments": {"assignments": [{"id": "fb308822-842f-4559-b5c9-96853c79e00e", "name": "encoded_html", "type": "string", "value": "={{JSON.stringify( $json.html )}} "}, {"id": "390b747b-967d-45f4-9faf-3aaed605d769", "name": "encoded_plaintext_body", "type": "string", "value": "={{JSON.stringify($json.text)}} "}]}}, "typeVersion": 3.4}, {"id": "90158667-eeda-4d44-b45c-c6e7fa02e664", "name": "If campaign is modified recently", "type": "n8n-nodes-base.if", "position": [1420, 200], "parameters": {"options": {}, "conditions": {"options": {"version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict"}, "combinator": "and", "conditions": [{"id": "7e9c9fd3-2ef9-47ce-bccb-9b3320472d36", "operator": {"type": "dateTime", "operation": "after"}, "leftValue": "={{ $json.update_date }}", "rightValue": "={{ $json.updated_at }}"}]}}, "typeVersion": 2.2}, {"id": "55aecc9b-d5a6-4a6b-a986-3ddfae200b94", "name": "Filter Braze vs Dartagnan", "type": "n8n-nodes-base.if", "position": [1440, 420], "parameters": {"options": {}, "conditions": {"options": {"version": 2, "leftValue": "", "caseSensitive": true, "typeValidation": "strict"}, "combinator": "and", "conditions": [{"id": "7e9c9fd3-2ef9-47ce-bccb-9b3320472d36", "operator": {"type": "string", "operation": "exists", "singleValue": true}, "leftValue": "={{ $json.unified_name }}", "rightValue": "="}]}}, "typeVersion": 2.2}, {"id": "ff2a47df-983f-42f5-9c96-431fccbdb8ef", "name": "Embed image in HTML", "type": "n8n-nodes-base.code", "position": [1960, 180], "parameters": {"jsCode": "// n8n Code Node: HTML Image URL Replacer\n// This script replaces all image references in HTML with their direct URLs\n// It's designed to work with the data structure you provided\n\n/**\n * Main function to process the incoming data in n8n\n * Expects an item with html and medias properties\n */\nfunction processData(item) {\n // Extract the HTML and media mappings from the item\n const { html, medias } = item.json;\n\n // Process the HTML and replace all image references\n const processedHtml = replaceImageReferences(html, medias);\n\n // Return the processed data\n return {\n json: {\n ...item.json,\n html: processedHtml\n }\n };\n}\n\n/**\n * Replace all image references in HTML with direct URLs\n * @param {string} html - The HTML content to process\n * @param {Object} medias - Key-value pairs mapping image paths to direct URLs\n * @returns {string} - Processed HTML with direct URLs\n */\nfunction replaceImageReferences(html, medias) {\n if (!html