Facebook Webhooks get unsubcribed after first webhook recieved

I am using a “Facebook Trigger” node to recieve webhooks about “feed” of one of my pages. I set it up on my n8n and also on Facebook App Dashboard: I mean I subscribe my Facebook App to “Page” object, and the “Callback URL” and the “challenge”.

When I recieve the first notification (for example, a comment on one of the posts of my page) it works, and I recieve it on n8n and it gets processed. But after that, if I check my Facebook App’s subcription I see now it is not subscribed to any Webhook.

It gets unsubscribed everytime after the first webhook recieved. Anyone with the same problem?

Welcome to the community @ruccc !

Do you activate the workflow via the toggle on the top right of the page? Because if you run the workflow manually to test & debug by pressing “Execute Workflow” it will work only for one call. Only if you run it in production mode by activating it, will it stay registered long term.

1 Like

Oh, ok, thanks!

This way is very difficult to debug the workflow… I have to re-subscribe everytime to the Facebook Webhook.

Hey @ruccc!

I’ve tried the node before, and I set up the Webhook URL once. I only had to send test data from the Facebook Developer Console, and I didn’t have to subscribe every time. I am not sure if Facebook changed anything on their end.

I’ve had the same experience recently: subscriptions have to be re-activated on the facebook app side every time the n8n workflow is activated, whether whether for production or testing. It’s not insurmountable but a bit tedious during testing.

Perhaps a solution would be to add the desired subscriptions to the trigger node? I don’t know if that’s possible through the facebook apis.

All in all, though, the facebook node works great!

Just to update, I was able to automate the subscription by making an api call to {{api_id}}/subscriptions on workflow save and activate. In the long run, it’d be nice for the Facebook trigger node to manage subscriptions itself, but here’s a working example in the meantime.

{
  "nodes": [
    {
      "parameters": {
        "events": [
          "activate",
          "update"
        ]
      },
      "name": "Workflow Trigger",
      "type": "n8n-nodes-base.workflowTrigger",
      "typeVersion": 1,
      "position": [
        200,
        380
      ]
    },
    {
      "parameters": {
        "httpRequestMethod": "POST",
        "node": "{{app_id}}}", //put your app_id here
        "edge": "subscriptions",
        "allowUnauthorizedCerts": true,
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "object",
                "value": "page"
              },
              {
                "name": "fields",
                "value": "leadgen" //or whatever subscriptions you want
              }
            ]
          }
        }
      },
      "name": "Subscribe to Webhooks",
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        370,
        380
      ],
      "credentials": {
        "facebookGraphApi": "Credentials with App token"
      },
      "notes": "leadgen"
    }
  ],
  "connections": {
    "Workflow Trigger": {
      "main": [
        [
          {
            "node": "Subscribe to Webhooks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes

So, if I understand, everytime you run the scenario you subscribe to the Facebook Webhook again via an API call. Right?

I find that Webhooks get unsubcribed from time to time, even if I don’t run the scenario manually. Yesterday I left my scenario on n8n working, and today I woke up and the Webhook field was unsubcribed. I haven’t touched n8n during the night, obviously…

I wonder if the subscription is expiring for some reason. According to the link below, it’s possible when certain actions are taken within the facebook account.

This link is about Access Tokens, not Subscriptions.

I don’t know how Facebook Trigger node handles the subscriptions, but is very misterious. Sometimes you get unsubscribed only from the fields (feed, mentions, story_insights…), sometimes you get unsubscribed from the whole edge (User, Page, Instagram…).

I don’t undesrtand why is this way. It would be easier if it just stays subscribed allt he time, as it should be…

Yep, that’s right.

I’m not especially familiar with the Facebook api, but if the problem is on the n8n side it’s possible your n8n instance (or just this workflow?) is restarting automatically somehow. If that’s the case, this might fix it.

mmm… I don’t think so, now it’s working good for a week. But today it got unsubscribed, on of the edges of Facebook, I don’t know why.

I think that the “problem” is that everytime you recieve a call via Facebook Webhook, if your are manually starting the workflow, it gets automatically unsubscribed. If you are not even on n8n it doesn’t seems to get unsubscribed.

@this-gavagai looks like was having a similar problem.

Yep, @this-gavagai is me :slight_smile:

Per the node source code, subscriptions are created and deleted when the workflow is activated and deactivated. It shouldn’t be happening every time the workflow runs. Facebook doesn’t provide much logging, unfortunately, but I’d wonder if your n8n logs would show when/why the workflow is getting deactivated.

Mmm… But I never deactivate my workflow, I do manually run it sometimes, and that’s when it gets the Webhook unsubscribed (sometimes just the edge, sometimes the whloe webhook subscription - I don’t know when is one option and when is the other…).

How can I have access to my n8n logs to search for this?

PD: wouldn’t it be easier to just don’t unsubscribe the Facebook Webhook once it is subscribed? I don’t get the point of it… :S

Running the workflow manually is, I think, effectively the same as deactivating, since it requires the trigger to terminate and restart. If you do that, you’ll also need to resubscribe your webhooks.

Mmm… But I never deactivate my workflow, I do manually run it sometimes, and that’s when it gets the Webhook unsubscribed (sometimes just the edge, sometimes the whloe webhook subscription - I don’t know when is one option and when is the other…).

So you deactivate the workflow to run it manually and then activate it again?

PD: wouldn’t it be easier to just don’t unsubscribe the Facebook Webhook once it is subscribed? I don’t get the point of it… :S

Because depending on the webhook API that we are consuming that might be an issue. Some APIs do not let you have more than one “subscription” at the same. So we need to provide a way to delete easily from n8n instead of having to go API’s UI and delete it manually. There is more to it.

How can I have access to my n8n logs to search for this?

Not sure if the logs will give you the answer you are looking for.

There are multiple scenarios where a “subscription” is deactivated.

  1. You run a trigger in test mode (from the UI), and the trigger receives data.

  2. You run a trigger in test mode (from the UI), and it does not receive data within 2 minutes

  3. You deactivate a workflow previously active (production mode).

I’ve had the same experience recently: subscriptions have to be re-activated on the Facebook app side every time the n8n workflow is activated, whether whether for production or testing. It’s not insurmountable but a bit tedious during testing.

I’m looking into this. That should not happen. What to d you mean exactly with subscriptions have to be re-activated on the Facebook app side? Can you provide an example? I have no experience with Facebook whatsoever.

Sure thing. I’m not sure which parts you’re familiar with and which parts you aren’t, so I’ll just start at the beginning. Apologies if any of it is obvious or repetitive!

Facebook, like many software platforms, provides access to APIs and services through developer applications, which get created at https://developers.facebook.com. Once an app has been created, you can add a range of different “products”, such as OAuth login, messenger access, web payments, analytics, etc.

In n8n, the facebook trigger node is concerned with the “Webhooks” product. As the name implies, webhooks will cause the app to call an arbitrary http endpoint with data when certain events happen within a facebook account, such as new timeline posts, changes to profile pictures, chat sessions, billing transactions, etc. But, in order to get notified about a particular type of data, you have to subscribe to it.

This subscription process has two parts: first you subscribe to an object, and then second you select which fields of that object you want to be notified about. The n8n facebook trigger node handles the first part but not the second.

When creating a new facebook trigger node, you have to specify which object you would like to subscribe to. There are, at present, 8 different objects, including “page”, “user”, “application”, etc. When the node is activated, the object subscription is created, and when the node is deactivated, it is destroyed. That all works as it should.

The problem is that, in addition to object subscriptions, it is also necessary to subscribe to fields. The “page” object, for example, has several dozen different fields, including “bio”, “birthday”, “feed”, “name”, “phone”, “leadgen”, etc. Each field represents a particular data structure for which change notifications can be created. If you subscribe to “feed”, for example, your webhook endpoint will get called when a new post is made to the page. If you subscribe to “leadgen”, it will get called when somebody fills out a leadgen form. When a new object subscription is created, it won’t do anything unless at least some of these fields are also subscribed to.

At present, when a new object subscription is created, no field subscriptions are made. They must be made at the facebook application developer console. That wouldn’t be a huge problem if those field subscriptions were permanent, but they aren’t. When the trigger node is deactivated for any reason, the object subscription is destroyed. When it gets activated again the subscription is created without any fields selected. The facebook trigger node does not at present “remember” which fields an application subscribes to. It only remembers the object.

I’ve described a somewhat clumsy solution to this problem above, but a better solution would be for the facebook trigger node to specify not just the subscription object but also the subscription field(s).

1 Like

Thanks very much for the detailed explanation. I was confused. I was able to fix the issue. Now you can set the fields you want to subscribe to when creating the webhook. @ruccc this PR should solve the issue you were having. We will let you know when it’s released.

3 Likes

Wow, thank you! I will check once it’s released.

And thank you @this-gavagai for the detailed explanation that helped into this!