Wowza Community

Create endpoint for webhook via API

Hi there,

Is there any way or any plan to allow a webhook endpoint to be created dynamically via the API? We create sites and the associated live_streams, recordings etc. dynamically and it would be great if they could receive events directly (either as an ID or URL as a parameter when creating using the API) and even better if they could receive only their own events (though handling that filtering in the webhook is fine too).

We’ve talked about receiving webhooks centrally and forwarding them to the relevant site but it does add a point of failure I’d prefer to avoid if possible.

Can you explain this in more details?

it would be great if they could receive events directly (either as an ID or URL as a parameter when creating using the API) - What are events here? which ID/URL do you refer to? can you perhaps explain with an example?

You can always create your own API and build the mechanism for webhooks.

You can always create your own API and build the mechanism for webhooks

Hi @Daniel_Taylor, following up on @Connessione’s message, if you want to create a custom Wowza module (plug-in) that can call your own webhooks on certain events then here’s some code that we wrote a while ago.

public class ModulePublishWebhook extends ModuleBase {
	private IMediaStreamActionNotify2 actionNotify;
	private IApplicationInstance      appInstance;
	
	private String baseURL;
	private String publishPath;
	private String unPublishPath;
		
	class StreamListener implements IMediaStreamActionNotify2 {
		@Override
		public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
			doCall(publishPath, streamName);
		}

		@Override
		public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) {
			doCall(unPublishPath, streamName);
		}
		
		public void doCall(String path, String streamName) {
			try {
				HttpPost            post    = new HttpPost(baseURL + "/" + path);
				List<NameValuePair> params  = new ArrayList<NameValuePair>(2);
				
				params.add(new BasicNameValuePair("application", appInstance.getApplication().getName() ));
				params.add(new BasicNameValuePair("stream", streamName));
				
				post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
			
				CloseableHttpClient client = HttpClients.createDefault();
				
				client.execute(post);
			
			} catch (Exception e) {
				getLogger().error("An error occurred while calling the webhook", e);
			}
		}
	}
	
	public void onAppStart(IApplicationInstance appInstance) {
		this.actionNotify  = new StreamListener();
		this.appInstance   = appInstance;
		this.baseURL       = appInstance.getProperties().getPropertyStr("webhook.baseurl", "");
		this.publishPath   = appInstance.getProperties().getPropertyStr("webhook.publish", "");
		this.unPublishPath = appInstance.getProperties().getPropertyStr("webhook.unpublish", "");
	}

	public void onStreamCreate(IMediaStream stream) {
		stream.addClientListener(this.actionNotify);
	}

	public void onStreamDestroy(IMediaStream stream) {
		if (this.actionNotify != null) {
			stream.removeClientListener(this.actionNotify);
		}
	}
}
1 Like

There is also an option for using/taking-hints-from the older Wowza module - wse-plugin-analytics which was originally designed to send out important events to google analytics and/or custom HTTP endpoints.

1 Like

I just meant, when creating the live_stream via the Wowza Video Rest API, having the ability to either add a URL for webhooks to get sent to or provide a webhook endpoint ID if creating the webhook was a separate API call. The events we want are pretty much covered in the existing webhook integration at /manage/integrations . The only issue was that the endpoints we’d need would be created automatically and nothing else in our process requires manual intervention at the moment. Right now it sounds like having a central endpoint to forward the webhooks is the only way to go, I was just curious if there was something existing to help with this use case.

Regarding the modules - we’re not using Wowza Streaming Engine in most cases so I don’t think this would work for us(?)

Thanks for the quick replies anyway, much appreciated!

Ah, i see. Sorry, my bad. i misunderstood the problem domain.