Trying to create separate Stream accounts for webhooks to separate URLs

We have the same website hosted at 2 URLs for our different environments. For example:

https://abc.com - production website instance
https://dev.abc.com - development website instance

We are using Stream for video hosting and till now using the same Stream account for both of the environments. However, we need to setup webhooks now to be notified when a video processing has been completed and only then start showing that video in the feed.

However, the documentation over here states that we can only setup a single webhook per Cloudflare account. But we need to hit separate webhooks for the 2 environments. If a video has been uploaded from the dev environment, the webhook has to be posted to an API on the dev environment for the right video record in the database to be updated. Same goes for the production environment.

Please let us know how to proceed

Do you already have two different Cloudflare accounts to represent “dev” and “prod” environments?

If you did, then you could configure the webhook URL for your Stream Dev account to your dev server and the webhook in Stream Prod account to your prod server right? Let me know if I am misunderstanding something.

It doesn’t seem that way. It looks like they’re both in the same zone, which would make it difficult to split into two Cloudflare accounts.

Got it. I was a bit confused reading the title of the post which implies separate accounts.

My advise to the OP would be to set up a separate Cloudflare account for dev environment. We plan to make major upgrades to webhooks in coming quarters so we can support multiple URLs from a single cloudflare account. Having entirely separate cf account would be the best interim solution.

The other workaround if you really want to avoid a separate account is to write a Worker and point all webhook requests to that worker. The Worker can then determine if its a prod or dev video and reroute the request to the appropriate dev/prod endpoints on your origin.

They’d have to move their dev environment to a completely different domain. And it would have to be on a separate Cloudflare account.

We dont have separate Cloudflare accounts.

That would be a last resort as that would mean I would need separate email accounts. As this is a work account, I would then need to setup separate email accounts on this domain or an account on a different domain.

I would also have to setup a new domain on the new account that I would need to create and connect cloudflare to the same. Then I would need to move my dev environment from dev.abc.com to xyz.com

Finally, I would need to procure a new Cloudflare Stream subscription for the same.

This is absolutely a last resort. I would prefer if there were an easier solution.

It would be preferable if this could be avoided. Any other workarounds?

The easiest workaround would be to setup a Cloudflare Worker script and configure Stream to send all requests to it. The Worker script can redirect the request to your prod or staging environment.

I’ve put together a quick example here: stream-examples/webhook-redirect-worker.js at main · zaidf/stream-examples · GitHub

In my example, if the video file name contains “staging-”, the webhook will be sent to the staging URL configured at the top of the script. All other requests will goto prod.

2 Likes

Thank you for the example. However, it would require us to maintain another API on Cloudflare and get billed for it separately.

So, we ended up going with a interval based polling solution that will query the Cloudflare API for stream readiness check and mark the video processed if cloudflare responds with “ready”

1 Like

Got it. Please note that Workers provides a free tier with 100K free requests/day: https://developers.cloudflare.com/workers/platform/limits#worker-limits

If there is an option to send the webhook URL along with the upload request, that would be very much easier. We use payment gateways on which we can send a callback URL for that transaction along with the request parameters. That would be much easier.

Because I use stream subscription as a common subscription service for two different domains. It is not possible to have a single webhook URL here. I need to add a third domain common for these two domains and create a separate POST request from the third domain to either of the two.

Or at least, one webhook subscription per domain added in the Cloudflare account would be helpful.

Hi there. We don’t have an option for sending a webhook URL with the request. But have you considered adding specific meta data to the video in the meta field at the time of upload? Then, you can create a Worker (similar to one I shared) that redirects the webhook requests from Stream to your use-case specific webhook processing script. For example, you could include the domain in the meta field and then have the Worker redirect the webhook to different destinations based on the domain in the meta field.

1 Like

Hi Zaid,

Thank you for the valuable idea. It really helped. I just passed the endpoint URL in the meta. Thanks for the great tutorial.

HI Zaid

We’re looking for an option to upload videos to different “folders” depending on whether we’re in development or production, ideally from within the same account because quite frankly no one wants to manage multiple accounts.

Suppose I use a meta field named “environment”, in which the value could be “development” or “production”, how do I filter my videos by this meta field so that I can (for example) do some house cleaning and remove all development videos later on?

@eric19 this is a great question. Today we don’t offer a way to filter your videos by the meta field, but this is something we’d like to do. The solution I’d suggest for now is iterating through all your videos to find these videos. The API allows you to request up to 1000 videos at a time: Cloudflare API v4 Documentation

understood, thanks
hope the filter feature will be implemented soon

bump - would also love the ability to have multiple webhooks per stream account. A small number (one per environment) is fine, just more than one would be very useful. Thanks

Hi there, Stream currently only allows one webhook URL per account for on-demand videos. You could potentially use Cloudflare Worker to pipe all the webhooks to a Worker and then have your Worker relay the webhook data to multiple URLs.

You could modify this worker (stream-examples/webhook-redirect-worker.js at main · zaidf/stream-examples · GitHub) to pass the webhook to multiple URLs.