Creating a webhook through API
Create a webhook with POST /webhook, then send it a test event.
Skip the reading — fast path for coding agents
truto webhooks create --target-url https://example.com/truto-webhook
/skill truto
curl --location 'https://api.truto.one/webhook' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TRUTO_API_TOKEN" \
--data '{
"target_url": "https://webhook.site/6a7cc86e-9286-4be8-ba79-bcd8dfdbeee1",
"is_active": true,
"event_types": ["integrated_account:created"]
}'truto webhooks create -b '{
"target_url": "https://webhook.site/6a7cc86e-9286-4be8-ba79-bcd8dfdbeee1",
"is_active": true,
"event_types": ["integrated_account:created"]
}'from truto_python_sdk import TrutoApi
truto_api = TrutoApi(token="<api_token>")
webhook = await truto_api.webhooks.create({
"target_url": "https://webhook.site/6a7cc86e-9286-4be8-ba79-bcd8dfdbeee1",
"is_active": True,
"event_types": ["integrated_account:created"],
})In the example request above,
target_urlis the webhook endpoint where a POST request with the webhook payload as the request body will be made. It must be a publichttps://URL; see Errors.is_active: optional, defaults totrue.event_typesis an array of webhook event types that thetarget_urlshould receive data for. It is optional and if not mentioned in the request, then thetarget_urlwill receive data for all webhook event types.
The request returns 201 with the webhook,
{
"id": "b6d29b9b-3d9d-44fd-aa77-512fd83b28c1",
"target_url": "https://webhook.site/6a7cc86e-9286-4be8-ba79-bcd8dfdbeee1",
"secret": "6e17561c-a20c-44ce-b8b5-caff0bf786fe",
"is_active": true,
"environment_id": "ac15abdc-b38e-47d0-97a2-69194017c199",
"event_types": ["integrated_account:created"],
"created_at": "2023-06-15T14:40:03.000Z",
"updated_at": "2023-06-15T14:40:03.000Z"
}event_typeslists the subscribed event types. It is["all"]when the request did not specify any.secretis returned only in this response. Fetching or listing webhooks later does not include it, so store it securely now. Use it to verify theX-Truto-Signatureheader on each event Truto sends. Thesecretis unique to each webhook that you create, and Truto generates it: asecretsent in the create request is ignored. See verifying webhook events.
Send test event
Send the webhook a test event with POST /webhook/test:
curl --location 'https://api.truto.one/webhook/test' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TRUTO_API_TOKEN" \
--data '{
"id": "b6d29b9b-3d9d-44fd-aa77-512fd83b28c1",
"event_type": "integrated_account:created"
}'truto webhooks test --id b6d29b9b-3d9d-44fd-aa77-512fd83b28c1 --event-type integrated_account:createdresult = await truto_api.webhooks.test(
"b6d29b9b-3d9d-44fd-aa77-512fd83b28c1",
event_type="integrated_account:created",
)idis the ID of the webhook to send the test event to.event_typeis optional and defaults tointegrated_account:created. It can be any event type from the list of webhook event types exceptall.integrated_account_idis optional. When set, the test payload is built from that integrated account, which must belong to the webhook's environment.payloadis an optional object deep-merged into the generated test payload.
A test event is sent once, isn't retried and isn't kept in event history. It goes to the webhook even when the webhook is turned off or doesn't subscribe to that event type. Without integrated_account_id, the payload uses placeholder IDs.
A successful test returns the event that was sent (trimmed here),
{
"success": true,
"event_type": "integrated_account:created",
"payload": {
"id": "00000000-0000-4000-8000-00000000ac01",
"tenant_id": "truto-test-tenant",
"environment_id": "ac15abdc-b38e-47d0-97a2-69194017c199",
"status": "connecting",
"integration": {
"id": "00000000-0000-4000-8000-000000000001",
"name": "hubspot",
"config": { "label": "HubSpot" }
},
"…": "…"
}
}If your endpoint responds with a non-2XX status code, the request fails with a 500 error whose message includes the status code and response body your endpoint returned.
Update or delete a webhook
Change a webhook with PATCH /webhook/{id}. It takes target_url, is_active and event_types.
curl --location --request PATCH 'https://api.truto.one/webhook/b6d29b9b-3d9d-44fd-aa77-512fd83b28c1' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $TRUTO_API_TOKEN" \
--data '{
"event_types": ["integrated_account:created", "integrated_account:active"]
}'truto webhooks update b6d29b9b-3d9d-44fd-aa77-512fd83b28c1 -b '{
"event_types": ["integrated_account:created", "integrated_account:active"]
}'import TrutoApi from '@truto/truto-ts-sdk'
const trutoApi = new TrutoApi({ token: process.env.TRUTO_API_TOKEN })
await trutoApi.webhook.update('b6d29b9b-3d9d-44fd-aa77-512fd83b28c1', {
event_types: ['integrated_account:created', 'integrated_account:active'],
})await truto_api.webhooks.update("b6d29b9b-3d9d-44fd-aa77-512fd83b28c1", {
"event_types": ["integrated_account:created", "integrated_account:active"],
})event_typesreplaces the list; it doesn't add to it. An empty list leaves the subscriptions as they are.- A new
target_urlmust follow the same rules as on create. is_active: falsestops deliveries. Turning a webhook off, or deleting it, also deletes its queued retries and its event history, so resend any failed events you need first. Turning it back on doesn't bring them back.
Delete a webhook with DELETE /webhook/{id}, or truto webhooks delete <id> in the CLI.
To change the secret, create a new webhook, move your endpoint to its secret, then delete the old one. While both webhooks point at your endpoint, it gets each event twice, once from each webhook, with a different id.
Errors
Create, and a PATCH that changes target_url, return 400 when the URL isn't a public https:// URL. The message says which rule it broke:
target_url must be a valid URLtarget_url must use httpstarget_url must not embed credentials: the URL has a username or password.target_url must not point to localhosttarget_url must not point to a private or reserved IP addresstarget_url must be a fully qualified hostname
An event type Truto doesn't know returns 400 with a message such as event_types contains 2 unknown event types: see unknown_event_types. The response's unknown_event_types lists up to 10 of them. Creating a webhook past your environment's limit also returns 400; see Webhooks overview.
Next
See Processing webhook events to verify the events your endpoint receives, and the Webhooks API reference for every endpoint.