Create a webhook
curl --request POST \
--url https://api.trench.dev/webhooks \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://your-webhook-url.com",
"enableBatching": true,
"eventTypes": [
"page",
"track",
"identify",
"group"
],
"eventNames": [
"UserSignedUp",
"UserLoggedIn"
],
"flatten": true
}
'import requests
url = "https://api.trench.dev/webhooks"
payload = {
"url": "https://your-webhook-url.com",
"enableBatching": True,
"eventTypes": ["page", "track", "identify", "group"],
"eventNames": ["UserSignedUp", "UserLoggedIn"],
"flatten": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
url: 'https://your-webhook-url.com',
enableBatching: true,
eventTypes: ['page', 'track', 'identify', 'group'],
eventNames: ['UserSignedUp', 'UserLoggedIn'],
flatten: true
})
};
fetch('https://api.trench.dev/webhooks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.trench.dev/webhooks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://your-webhook-url.com',
'enableBatching' => true,
'eventTypes' => [
'page',
'track',
'identify',
'group'
],
'eventNames' => [
'UserSignedUp',
'UserLoggedIn'
],
'flatten' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.trench.dev/webhooks"
payload := strings.NewReader("{\n \"url\": \"https://your-webhook-url.com\",\n \"enableBatching\": true,\n \"eventTypes\": [\n \"page\",\n \"track\",\n \"identify\",\n \"group\"\n ],\n \"eventNames\": [\n \"UserSignedUp\",\n \"UserLoggedIn\"\n ],\n \"flatten\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.trench.dev/webhooks")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://your-webhook-url.com\",\n \"enableBatching\": true,\n \"eventTypes\": [\n \"page\",\n \"track\",\n \"identify\",\n \"group\"\n ],\n \"eventNames\": [\n \"UserSignedUp\",\n \"UserLoggedIn\"\n ],\n \"flatten\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trench.dev/webhooks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://your-webhook-url.com\",\n \"enableBatching\": true,\n \"eventTypes\": [\n \"page\",\n \"track\",\n \"identify\",\n \"group\"\n ],\n \"eventNames\": [\n \"UserSignedUp\",\n \"UserLoggedIn\"\n ],\n \"flatten\": true\n}"
response = http.request(request)
puts response.read_body{
"uuid": "123e4567-e89b-12d3-a456-426614174000",
"url": "https://your-webhook-url.com",
"enableBatching": true,
"createdAt": "2021-01-01T00:00:00.000Z",
"eventTypes": [
"page",
"track",
"identify",
"group"
],
"eventNames": [
"UserSignedUp",
"UserLoggedIn"
],
"flatten": true
}Webhooks API
Create Webhook
Create a new webhook.
POST
/
webhooks
Create a webhook
curl --request POST \
--url https://api.trench.dev/webhooks \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://your-webhook-url.com",
"enableBatching": true,
"eventTypes": [
"page",
"track",
"identify",
"group"
],
"eventNames": [
"UserSignedUp",
"UserLoggedIn"
],
"flatten": true
}
'import requests
url = "https://api.trench.dev/webhooks"
payload = {
"url": "https://your-webhook-url.com",
"enableBatching": True,
"eventTypes": ["page", "track", "identify", "group"],
"eventNames": ["UserSignedUp", "UserLoggedIn"],
"flatten": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
url: 'https://your-webhook-url.com',
enableBatching: true,
eventTypes: ['page', 'track', 'identify', 'group'],
eventNames: ['UserSignedUp', 'UserLoggedIn'],
flatten: true
})
};
fetch('https://api.trench.dev/webhooks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.trench.dev/webhooks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://your-webhook-url.com',
'enableBatching' => true,
'eventTypes' => [
'page',
'track',
'identify',
'group'
],
'eventNames' => [
'UserSignedUp',
'UserLoggedIn'
],
'flatten' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.trench.dev/webhooks"
payload := strings.NewReader("{\n \"url\": \"https://your-webhook-url.com\",\n \"enableBatching\": true,\n \"eventTypes\": [\n \"page\",\n \"track\",\n \"identify\",\n \"group\"\n ],\n \"eventNames\": [\n \"UserSignedUp\",\n \"UserLoggedIn\"\n ],\n \"flatten\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.trench.dev/webhooks")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://your-webhook-url.com\",\n \"enableBatching\": true,\n \"eventTypes\": [\n \"page\",\n \"track\",\n \"identify\",\n \"group\"\n ],\n \"eventNames\": [\n \"UserSignedUp\",\n \"UserLoggedIn\"\n ],\n \"flatten\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.trench.dev/webhooks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://your-webhook-url.com\",\n \"enableBatching\": true,\n \"eventTypes\": [\n \"page\",\n \"track\",\n \"identify\",\n \"group\"\n ],\n \"eventNames\": [\n \"UserSignedUp\",\n \"UserLoggedIn\"\n ],\n \"flatten\": true\n}"
response = http.request(request)
puts response.read_body{
"uuid": "123e4567-e89b-12d3-a456-426614174000",
"url": "https://your-webhook-url.com",
"enableBatching": true,
"createdAt": "2021-01-01T00:00:00.000Z",
"eventTypes": [
"page",
"track",
"identify",
"group"
],
"eventNames": [
"UserSignedUp",
"UserLoggedIn"
],
"flatten": true
}This endpoint requires your private API key.
data field. Below is an example request body:
{
"data": [
{
"uuid": "b99b40c5-e306-4351-9f1d-9a13bb9e8bd1",
"type": "track",
"event": "ConnectedAccount",
"userId": "123e4567-e89b-12d3-a456-426614174000",
"properties": {
"totalAccounts": 4
},
"timestamp": "2024-10-21T21:32:17.000Z",
"parsedAt": "2024-10-21T21:32:23.194Z"
}
]
}
Body
application/json
Response
200 - application/json
The webhook has been successfully created. Requires private API key in Bearer token.
Was this page helpful?