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.
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 and the next page will show the status of the webhook:
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.