Skip to main content

Creating a webhook

There are two ways to create a webhook, either through the webhook dashboard or through the API of the ​OpenTicket system. As mentioned in introduction, you require an application that can receive POST-requests from the ​OpenTicket system before you create a webhook.

The ​OpenTicket system has various resources for which webhooks can be created. Listed below are the resources for which webhooks can be created and the triggers that can invoke the webhook for that resource.

CreateUpdateDeletePaidScanRelationReorder
Eventxxx
Ticketxxx
Productxxx
Orderxx
Scannerx

Dashboard​

You can create a webhook through the webhook dashboard as follows:

  1. Open the webhook dashboard
  2. Click the Create new button
  3. Change the Name and Destination URL
    • Name: a descriptive name of the webhook.
    • Destination URL: the URL that will receive the POST-requests.
  4. Select a resource and trigger in the dropdown menus
  5. Click the Create button

After you create a webhook, it will be listed on this dashboard.

Triggered by child resources​

It can be desirable to receive a webhook for any specific trigger related to a single resource. For example, a webhook receiving all newly created product- and ticket-types for some event. This is supported using the so-called Triggered by child resources option. The Triggered by child resources option, which allows users to create webhooks that are invoked by its direct triggers, but aso by triggers of related resources.

note

It used to be available to just "child" resources, but this is no longer the case. An apter name would thus be Triggered by related resources.

Triggers on some resource propagate to all webhooks registered on the same trigger with the Triggered by child resources option enabled, even when there is no webhook registered for that resource.

The following table shows which triggers on which resources can propagate. The columns depict the related sources belonging to the resources in the rows. Thus, when the resource in the depicted rows initiates a trigger directly, the columns show the resources the trigger can propagate to. The values in the cells depict the triggers.

EventTicketProductShopOrderScanner
Event------
TicketCreate, Update, Delete-----
ProductCreate, Update, Delete-----
ShopPaid, UpdatePaidPaid---
OrderCreate, Delete, ScanScanScan---
Scanner------

Consider an example where a webhook is configured for the Ticket resource on trigger "paid" with Triggered by child by resource enabled. When an Order — a related resource of Ticket — is paid, the Triggered by child resource setting triggers the webhook for the Ticket resource.

The same holds for a webhook for the Event resource on trigger "create". When enabling Triggered by child resources in the settings of this webhook, the webhook will also trigger when a Ticket or Product has been created.

API​

You can create a webhook through the API by making a POST-request to https://webhooks.openticket.tech. For this, you require the following information:

  • name: the name for the webhook.
  • url: the callback URL to which the POST-request notifications will be sent.
  • resource: the type of resource for which the webhook will be created.
  • trigger: the trigger that invokes the webhook. This is one of create, update, delete, relation, reorder or scan.
  • retries: maximum number of retries for failed POST-requests, see remarks.

In addition to the required information, you can supply the following information to the POST-request:

  • identifier: the GUID of a specific resource type for which the webhook should be created (for example, only invoke the webhook when a chosen event is updated).

See the code blocks below for examples of these requests and their expected response.

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer $accessToken"
],
CURLOPT_POSTFIELDS => [
"name" => "My Example Webhook",
"url" => "https =>//example.com/webhook/receive",
"resource" => "shop",
"trigger" => "create",
"retries" => 3
],
CURLOPT_URL => "https://webhooks.openticket.tech/webhook"
]);

$response = curl_exec($curl);
curl_close($curl);

echo $response;
This request results in the following response
{
"guid": "96007e9b-b570-454c-aa3b-66a33a88280a",
"created_at": "2023-07-19T09:43:50Z",
"updated_at": "2023-07-19T09:43:50Z",
"deleted_at": null,
"company_id": "d0a3f370-cd43-11ed-9c9c-bbcffde24a48",
"name": "My Example Webhook",
"url": "https://example.com/webhook/receive",
"retries": 3,
"resource": "ticket",
"identifier": "",
"nonce": "5aK2HMgcUlDCWLuC3KWa",
"trigger": "create",
"triggered_by_child_resources": false,
"invocations": null
}