Auto-update a Webhook Subscription (PubSubHubbub + YouTube)

After struggling a bit, and getting help here, I came up with this setup to make it easier to maintain a listener for push notifications from the Google PubSubHubbub Hub (and others, possibly).

Maybe there are more efficient ways to achieve this, but I would surely have benefited to find such tips when starting it n8n. I hope it can be useful for others too.

So, basically, you need 2 workflows: the first, is you regular workflow where do you want to run some actions; the second one is a workflow dedicated to subscribe and maintain your webhook updated and working, past the expiration period.

Lets take a look at the second one.

In this example, I setup a webhook to receive notifications every time a YouTube channel uploads or modifies a video.

It uses four kinds of nodes:

  • HTTP Request: to subscribe you webhook.
  • Webhook: to get your subscription verified by the Hub.
  • Cron: so that this workflow runs every 5 days, just before your webhook expires.
  • Set: to hold and format data needed within the workflow.

Copy the code bellow and replace these 3 parameter values in the respective nodes:

  • CHANNEL_ID: the sequence after ‘channel/’ as in https://www.youtube.com/channel/UCiHVTkJtWSdc9N3h0nUGWLg

    • ‘YouTube Settings’ node
  • WEBHOOK_PATH: a random unique alphanumeric sequence. Type anything or get one by adding a fresh webhook node.

    • ‘Webhook Settings’ node
    • ‘Webhook_Subscribe’ node
  • YOUR_DOMAIN: e.g example.com/

    • ‘Webhook Settings’ node

After pasting the code in your workflow, modify the parameters, pause the Start node, save the workflow and activate it.
Then, start the workflow by clicking at the small play button atop of the ‘Renew Subscription’ node.

image

To confirm that your Webhook was successfully verified, go to the Google PubSubHubbub Hub and use the Subscriber Diagnostics. Enter with:

  • the callback url (can be found in the webhook node); and
  • the topic url (YouTube video feedCHANNEL_ID)

After that, click in image and the next page will show the status of the webhook:
image

Now you can close this page and the workflow.

On a new workflow, insert a Webhook node and change the path to the same WEBHOOK_PATH used before.

Setup the rest of your workflow to take whatever actions and you want from the notifications and you don’t have to worry anymore about this webhook, as long as the previous workflow is active.

3 Likes

Hi, thanks for the guide @thiagonascimentodf :slight_smile:

I’m pretty new to n8n but I got it working.
For the first workflow, once it have been initialized, I had to disable Webhook_Subscribe to create the new webhook in my ‘handler’ workflow on the same WEBHOOK_PATH.

It seems that I receive multiple calls on my webhook from PubSubHubbub when a video is uploaded (at least 2) and I tried to ignore the second call if the first is already in execution calling the n8n API and checking if a workflow is running but it doesn’t seems to work :

How did you handle this ? Are you still using this workflow ?

Thanks a lot and sorry to update this topic after 2 years :smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.