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.
Create | Update | Delete | Paid | Scan | Relation | Reorder | |
---|---|---|---|---|---|---|---|
Event | x | x | x | ||||
Ticket | x | x | x | ||||
Product | x | x | x | ||||
Order | x | x | |||||
Scanner | x |
Dashboard​
You can create a webhook through the webhook dashboard as follows:
- Open the webhook dashboard
- Click the Create new button
- Change the
Name
andDestination URL
Name
: a descriptive name of the webhook.Destination URL
: the URL that will receive the POST-requests.
- Select a resource and trigger in the dropdown menus
- 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.
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.
Event | Ticket | Product | Shop | Order | Scanner | |
---|---|---|---|---|---|---|
Event | - | - | - | - | - | - |
Ticket | Create , Update , Delete | - | - | - | - | - |
Product | Create , Update , Delete | - | - | - | - | - |
Shop | Paid , Update | Paid | Paid | - | - | - |
Order | Create , Delete , Scan | Scan | Scan | - | - | - |
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.
- PHP
- GO
- Node
- Shell
$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;
payloadBuf := new(bytes.Buffer)
json.NewEncoder(payloadBuf).Encode({
"name": "My Example Webhook",
"url": "https://example.com/webhook/receive",
"resource": "shop",
"trigger": "create",
"retries": 3
})
req, _ := http.NewRequest("PUT", "https://webhooks.openticket.tech/webhook", bytes.NewBuffer(body))
req.Header.Add("Authorization", "Bearer " + accessToken)
resp, _ := http.DefaultClient.Do(req)
respBody, _ := io.ReadAll(resp.Body)
fmt.Println(string(respBody))
const options = {
"method": "POST",
"headers": {
"Authorization": `Bearer ${accessToken}`,
"Content-Type": "application/json"
},
"body": JSON.stringify({
"name": "My Example Webhook",
"url": "https://example.com/webhook/receive",
"resource": "shop",
"trigger": "create",
"retries": 3
})
};
fetch("https://webhooks.openticket.tech/webhook", options)
.then(response => response.json())
.then(response => console.log(response))
curl -X POST \
-H "Authorization: Bearer $accessToken" \
-F "name=My Example Webhook" \
-F "url=https://example.com/webhook/receive" \
-F "resource=shop" \
-F "trigger=create" \
-F "retries=3" \
"https://webhooks.openticket.tech/webhook"
{
"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
}