Creating a webhook through API
To create a webhook in Truto, call the webhook create endpoint.
An example webhook create request would look something like,
curl --location 'https://api.truto.one/webhook' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <api_token>' \
--data '{
"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.is_activeis an optional field which specifies if thetarget_urlshould receive webhook events.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 should yield a response like so,
{
"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. It must be used to verify the webhook event's signature, which can be foundX-Truto-Signatureheader of the request body of the webhook event. Thesecretis unique to each webhook that you create. See verifying webhook events.
Send test event
To send a test event to the webhook, call the webhook send test event endpoint.
curl --location 'https://api.truto.one/webhook/test' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <api_token>' \
--data '{
"id": "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 merged into the generated test payload.
A successful test returns the event that was sent,
{
"success": true,
"event_type": "integrated_account:created",
"payload": { ... }
}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.
API Reference
Refer Webhooks API reference for all the endpoints.