YouTube: Subscribe to Push Notifications

I am trying to trigger an action every time a specifc YouTube channel uploads a new video.

Tried several configurations using Webhook and HTTP Request nodes but couldn’t make it work.

I also followed the guidelines from YouTube>Data API>Guides>Subscribe to Push Notifications on how to use PubSubHubbub, but I seem to be lacking some very basic understanding of how to bring it all together.

The main problem I am facing is how to subscribed the Webhook and get it successfully verified.

Basically, I created a Webhook Node

Then, using the Test URL, hit Execute Node and, while Waiting for Webhook-Call is still active, I go to PubSubHubub and subscribe the Test URL along with the YouTube Channel Feed URL:

.

This returns a blank page with a Challenge mismatch. message.
At the Webhook I get a response with the challenge:

From the documentation, I gather that, to successfully verify the Webhook, I have to send back the challenge in the body of a POST request.

That is when I get the most confused. I tried many configurations

And was expecting to receive details about the channel updates, but this doens’t happen and even when this node doesn’t return an error,
image

as I check the Subscriber Diagnostics,

the subscription appears to be unverified:

My workflow:

What would be the correct way to receive the push YouTube notifications in my Webhook and from that, be able to send an e-mail, for example?

Hey @thiagonascimentodf!

I was trying to achieve something similar to this with Twitch and below is the workflow I used to verify the challenge.

{
  "nodes": [
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "challenge",
              "value": "={{$json[\"query\"][\"hub.challenge\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        690,
        240
      ]
    },
    {
      "parameters": {
        "path": "24666ee8-da1a-476e-abfe-dd33e6313367",
        "responseMode": "lastNode",
        "options": {
          "responsePropertyName": "challenge"
        }
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        490,
        240
      ],
      "webhookId": "24666ee8-da1a-476e-abfe-dd33e6313367"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Once the challenge is verified you can remove the Set node, and replace it with the Send Email node.

To help you better understand, these services require us to send back the challenge as a string. The Set node gets that challenge from the Webhook node. The ‘Last Node’ Response Mode, uses this value from the Set node to send back this challenge and verify the URL. You can read more on how to send a string response type for webhook here.

1 Like

Many thanks @harshil1712!!!

That was it!

After the Webhook was successfully verified, I just paused the Set node, so that I can reuse it later, if needed (e.g. updating or unsubscribing).

Additionally, I modified the Webhook to listen to POST requests.

Now it is working!

1 Like

I am glad it worked out! Have fun!

1 Like