Capture Facebook Click-to-WhatsApp Ad ID / Ref and send to Chatwoot via n8n

Hi everyone,

I am using the following setup:
Facebook / Instagram Click-to-WhatsApp Ads → WhatsApp Cloud API → Chatwoot (self-hosted)

When a user clicks a Facebook ad and starts a WhatsApp conversation, Meta sends referral information such as:

  • ref
  • ad_id
  • campaign_id
  • source

However, Chatwoot does not store or display this information by default, so we cannot see which ad or campaign the customer came from.

I want to use n8n to capture the WhatsApp webhook data, extract the referral information (ref, ad_id, campaign_id), and then send this data to Chatwoot as conversation attributes or contact attributes.

My idea workflow:
WhatsApp Webhook → n8n → Extract referral data → Chatwoot API → Update contact/conversation attributes

Questions:

  1. Has anyone implemented this workflow?
  2. How can I capture WhatsApp referral parameters from Meta webhook in n8n?
  3. Which Chatwoot API endpoint should I use to update contact attributes or conversation custom attributes?
  4. Is there an example n8n workflow for WhatsApp Cloud API → Chatwoot integration?

Any guidance or example workflows would be very helpful.

Thank you!

Hey! So yeah Meta does send the referral info in the webhook payload under messages[].referral but Chatwoot just ignores it, there’s actually an open feature request for this on their GitHub. Your n8n middleman approach is the right call. Youd set up a Webhook node to catch the Meta payload, pull out the ref/adid/campaignid from the referral object, then hit the Chatwoot API to update the contact’s customattributes via PATCH /api/v1/accounts/{accountid}/contacts/{contact_id}. Something like this should work

Youll need to figure out the Chatwoot contact ID lookup part, easiest way is to search by phone number using GET /api/v1/accounts/{id}/contacts/search?q={phone} before the PATCH or if youre already syncing contacts you might have it stored somewhere. Just swap in your Chatwoot URL and set up the header auth with your API access token.

the whatsapp payload from meta should include those referral params in the message data. check the chatwoot api docs for the custom attributes endpoint (usually POST /api/v1/contacts/:id/custom_attributes or similar). main thing is mapping the meta structure to what chatwoot expects. have you logged the raw webhook to see what’s actually coming through?

I’ve worked extensively with Facebook Graph API webhooks in n8n so can add a bit here.

One thing to watch: Meta’s WhatsApp webhook sends the referral data inside messages[0].referral but only on the FIRST message of a conversation started from an ad. If you miss that first webhook event you lose the attribution data permanently.

So I’d recommend storing the referral info immediately when you receive it, before doing anything else in the workflow.

For the Chatwoot side, the endpoint to update contact custom attributes is:
PATCH /api/v1/accounts/{account_id}/contacts/{id}

With body like:

{
  "additional_attributes": {
    "ad_id": "123",
    "campaign_id": "456",
    "ref": "summer_promo"
  }
}

The tricky part is getting the contact_id in Chatwoot from the phone number. Use GET /api/v1/accounts/{id}/contacts/search?q={phone_number} first, then pass the contact_id to the PATCH call.

Also make sure your n8n webhook node handles the Meta webhook verification challenge (hub.challenge) or Meta will not send real events. This trips up a lot of people.

Let me know if you get stuck on any step.

Thanks to all ,

but i want to know that the webhook will be added to integration tab in chatwoot ? or is there something to do with facebook? , if in chatwoot so should i add an automation that send webhook events on that particular keywords , so i can save my n8n execution and all operation runs smoothly ? also i have kvm 4 of hostinger, so i dont think running chatwoot and n8n combine will be an issue with me

The n8n approach is the way to go — Chatwoot doesn’t have built-in Meta referral integration, so the middleware layer is needed. Your infrastructure should handle both systems without issues. Let’s see how the testing goes!

So the webhook goes in n8n not Chatwoot, you’d point your WhatsApp Cloud API webhook URL to your n8n Webhook node and n8n handles the rest. something like this should work

Youll need to add a step to look up the Chatwoot contact ID by phone number first (search contacts endpoint), but this is the basic idea. And yeah on a KVM 4 you’ll be fine running both.

so yeah i am asking that this webhook url will be added in my chatwoot here ? and also does whatsapp send the url of the advertisement in payload or not ? what whatsapp send the payload is there any idea or payload so i can create my workflow like that?

No, the webhook stays in n8n — point the WhatsApp Cloud API webhook URL directly to your n8n Webhook node. Chatwoot doesn’t receive the webhook directly.

For the WhatsApp payload, Meta sends the referral data in the first message of a conversation started from an ad. Check what’s actually hitting your n8n webhook with a simple log step — that’ll show you the exact structure. From there you map the fields to Chatwoot’s custom attributes.

The key thing is catching that first message; after that, the referral data is gone."

See i have created the facebook app which is connected through my chatwoot , and the webhook there is attached of my chatwoot , so you are saying that i need to change that webhook to my n8n webhook ?and then create the messaeg thrugh n8n thorugh chatwoot - api?

Is this how you are saying the workflow should look like ?