{
  "name": "HubSpot → Microsoft Ads Offline Conversions (direct API)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "hubspot-to-ms-ads",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -1120,
        192
      ],
      "id": "0b57fbf1-c759-4551-bd0e-ae38ce4acd2d",
      "name": "Webhook"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "operation": "get",
        "contactId": {
          "__rl": true,
          "value": "={{ $json.body[0].objectId }}",
          "mode": "id"
        },
        "additionalFields": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "msclkid",
                "lifecyclestage",
                "mql_uploaded_to_ms_ads",
                "sql_uploaded_to_ms_ads"
              ]
            }
          }
        }
      },
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        -448,
        96
      ],
      "id": "2a6abcde-fc67-4c0d-b5d3-73750b088741",
      "name": "Get a contact",
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "HubSpot OAuth2"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "deal",
        "operation": "get",
        "dealId": {
          "__rl": true,
          "value": "={{ $json.body[0].objectId }}",
          "mode": "id"
        },
        "filters": {
          "propertiesCollection": {
            "propertiesValues": {
              "properties": [
                "closedwon_uploaded_to_ms_ads",
                "amount",
                "closedate",
                "dealstage",
                "msclkid",
                "amount_in_home_currency"
              ]
            }
          }
        }
      },
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        -448,
        384
      ],
      "id": "ceecd1c6-aa00-4fe9-8fb7-5a1e745f8617",
      "name": "Get a deal",
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "HubSpot OAuth2"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://campaign.api.bingads.microsoft.com/CampaignManagement/v13/OfflineConversions/Apply",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "sendHeaders": true,
        "specifyHeaders": "json",
        "jsonHeaders": "{\n  \"Content-Type\": \"application/json\",\n  \"CustomerAccountId\": \"YOUR_CUSTOMER_ACCOUNT_ID\",\n  \"CustomerId\": \"YOUR_CUSTOMER_ID\",\n  \"DeveloperToken\": \"YOUR_DEVELOPER_TOKEN\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"OfflineConversions\": [\n    {\n      \"MicrosoftClickId\": \"{{ $json.properties.msclkid.value }}\",\n      \"ConversionName\": \"MQL\",\n      \"ConversionTime\": \"{{ $now.toISO() }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        224,
        0
      ],
      "id": "13d2b0f3-d162-43b2-b2a8-bbec98847475",
      "name": "Upload MQL to Ms Ads",
      "credentials": {
        "oAuth2Api": {
          "name": "Microsoft Ads OAuth2"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://campaign.api.bingads.microsoft.com/CampaignManagement/v13/OfflineConversions/Apply",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "sendHeaders": true,
        "specifyHeaders": "json",
        "jsonHeaders": "{\n  \"Content-Type\": \"application/json\",\n  \"CustomerAccountId\": \"YOUR_CUSTOMER_ACCOUNT_ID\",\n  \"CustomerId\": \"YOUR_CUSTOMER_ID\",\n  \"DeveloperToken\": \"YOUR_DEVELOPER_TOKEN\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"OfflineConversions\": [\n    {\n      \"MicrosoftClickId\": \"{{ $json.properties.msclkid.value }}\",\n      \"ConversionName\": \"SQL\",\n      \"ConversionTime\": \"{{ $now.toISO() }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        224,
        192
      ],
      "id": "dd66ddcd-ef94-4d68-9edd-f4320cacd535",
      "name": "Upload SQL to Ms Ads",
      "credentials": {
        "oAuth2Api": {
          "name": "Microsoft Ads OAuth2"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://campaign.api.bingads.microsoft.com/CampaignManagement/v13/OfflineConversions/Apply",
        "authentication": "genericCredentialType",
        "genericAuthType": "oAuth2Api",
        "sendHeaders": true,
        "specifyHeaders": "json",
        "jsonHeaders": "{\n  \"Content-Type\": \"application/json\",\n  \"CustomerAccountId\": \"YOUR_CUSTOMER_ACCOUNT_ID\",\n  \"CustomerId\": \"YOUR_CUSTOMER_ID\",\n  \"DeveloperToken\": \"YOUR_DEVELOPER_TOKEN\"\n}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"OfflineConversions\": [\n    {\n      \"MicrosoftClickId\": \"{{ $json.properties.msclkid.value }}\",\n      \"ConversionName\": \"Closed Won\",\n      \"ConversionTime\": \"{{ $now.toISO() }}\",\n      \"ConversionValue\": {{ $json.properties.amount_in_home_currency.value }},\n      \"ConversionCurrencyCode\": \"EUR\"\n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        224,
        384
      ],
      "id": "b1fcab3a-f807-44bf-bb38-86c543ec95d4",
      "name": "Upload Closed Won to Ms Ads",
      "credentials": {
        "oAuth2Api": {
          "name": "Microsoft Ads OAuth2"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "email": "={{ $('Get a contact').item.json.properties.email.value }}",
        "additionalFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "mql_uploaded_to_ms_ads",
                "value": "true"
              }
            ]
          }
        },
        "options": {}
      },
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        448,
        0
      ],
      "id": "62517cac-69db-4f21-8578-c44cff1b4293",
      "name": "MQL Flag Update",
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "HubSpot OAuth2"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "email": "={{ $('Get a contact').item.json.properties.email.value }}",
        "additionalFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "sql_uploaded_to_ms_ads",
                "value": "true"
              }
            ]
          }
        },
        "options": {}
      },
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        448,
        192
      ],
      "id": "0eec662d-136a-46fa-bdf3-25b2911ad316",
      "name": "SQL Flag Update",
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "HubSpot OAuth2"
        }
      }
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "deal",
        "operation": "update",
        "dealId": {
          "__rl": true,
          "value": "={{ $('Get a deal').item.json.dealId }}",
          "mode": "id"
        },
        "updateFields": {
          "customPropertiesUi": {
            "customPropertiesValues": [
              {
                "property": "closedwon_uploaded_to_ms_ads",
                "value": "true"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.hubspot",
      "typeVersion": 2.2,
      "position": [
        464,
        384
      ],
      "id": "3e144c8c-8c4a-4efe-a181-1534f3201a59",
      "name": "Closed Won Flag Update",
      "credentials": {
        "hubspotOAuth2Api": {
          "name": "HubSpot OAuth2"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.body[0].subscriptionType }}",
                    "rightValue": "contact.propertyChange",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "05b69081-d59a-4aa5-b223-874984f1e1a4"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Contact Events"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "80550c42-cefd-4fd3-ae78-ca7b2b1b0aaf",
                    "leftValue": "={{ $json.body[0].subscriptionType }}",
                    "rightValue": "deal.propertyChange",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Deal Events"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -848,
        192
      ],
      "id": "f423d6f9-369a-4352-9862-357a79667842",
      "name": "Switch - Contacts and Deals"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.properties.lifecyclestage.value }}",
                    "rightValue": "marketingqualifiedlead",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "80bb112a-eb4b-4014-980e-31384868d802"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "MQL"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "9f402471-3acb-451e-bd01-dea3b61f9125",
                    "leftValue": "={{ $json.properties.lifecyclestage.value }}",
                    "rightValue": "salesqualifiedlead",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "SQL"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        -224,
        96
      ],
      "id": "1470d248-bc52-418e-bb2f-ff52e2790e94",
      "name": "Switch - MQL - SQL"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "9bf297a6-736b-4c99-819d-81f918dc869a",
              "leftValue": "={{ $json.properties.msclkid.value }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "d3e9ec60-007b-4590-be94-be220eecfbc8",
              "leftValue": "={{ $json.properties.mql_uploaded_to_ms_ads.value }}",
              "rightValue": "\"true\"",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        0,
        0
      ],
      "id": "8fe3b54f-80f5-484c-a347-10db45c7f7fc",
      "name": "If msclk=true AND flag=not true"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "9bf297a6-736b-4c99-819d-81f918dc869a",
              "leftValue": "={{ $json.properties.msclkid.value }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "d3e9ec60-007b-4590-be94-be220eecfbc8",
              "leftValue": "={{ $json.properties.sql_uploaded_to_ms_ads.value }}",
              "rightValue": "\"true\"",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        0,
        192
      ],
      "id": "445c6986-affd-45ee-ba4c-ada6d56bbe5b",
      "name": "If msclk=true AND flag=not true."
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "e7656ec1-a993-4171-a76c-18b512e11c3d",
              "leftValue": "={{ $json.properties.msclkid.value }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            },
            {
              "id": "32cd3177-4c08-42ab-a1d3-ab1b19690367",
              "leftValue": "={{ $json.properties.closedwon_uploaded_to_ms_ads.value }}",
              "rightValue": "\"true\"",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        -224,
        384
      ],
      "id": "4a87a2f5-d0e7-4df2-b28e-95e950fa79a7",
      "name": "If msclk=true AND flag= not true"
    }
  ],
  "pinData": {},
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Switch - Contacts and Deals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a contact": {
      "main": [
        [
          {
            "node": "Switch - MQL - SQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a deal": {
      "main": [
        [
          {
            "node": "If msclk=true AND flag= not true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload MQL to Ms Ads": {
      "main": [
        [
          {
            "node": "MQL Flag Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload SQL to Ms Ads": {
      "main": [
        [
          {
            "node": "SQL Flag Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Closed Won to Ms Ads": {
      "main": [
        [
          {
            "node": "Closed Won Flag Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch - Contacts and Deals": {
      "main": [
        [
          {
            "node": "Get a contact",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get a deal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch - MQL - SQL": {
      "main": [
        [
          {
            "node": "If msclk=true AND flag=not true",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If msclk=true AND flag=not true.",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If msclk=true AND flag=not true": {
      "main": [
        [
          {
            "node": "Upload MQL to Ms Ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If msclk=true AND flag=not true.": {
      "main": [
        [
          {
            "node": "Upload SQL to Ms Ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If msclk=true AND flag= not true": {
      "main": [
        [
          {
            "node": "Upload Closed Won to Ms Ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "tags": []
}