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 | Relation | Reorder | Scan | |
---|---|---|---|---|---|---|
Event | x | x | x | x | ||
Order | x | x | x | x | ||
Ticket | x | x | x | x | ||
Metadata | x | x | 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.
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"