Sorry, no results found for "".
Parameters to control offset-based pagination
The (zero-based) offset of the first entity returned in the collection (defaults to 0)
The maximum number of entities to return (defaults to 30, maximum is 500)
Attributes to filter
IDs to fetch, comma separated
"42,554"
The subject of webhook triggering
"item"
The event that triggers the webhook call
"update"
The current status
"success"
The delivery attempt is currently in process
Delivery completed successfully
Delivery attempt(s) failed due to errors/timeouts
The last delivery attempt failed, a new one will be retried later
Fields used to order results
"name_DESC"
Returns an array of resource objects of type webhook_call
import { buildClient } from "@datocms/cma-client-node";
async function run() { // Make sure the API token has access to the CMA, and is stored securely const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
const webhookCalls = await client.webhookCalls.list(); console.log(webhookCalls);}
run();
[ { id: "84033321", type: "webhook_call", request_url: "https://www.example.com/webhook", request_payload: '{ \ "environment": "main", \ "entity_type": "item", \ "event_type": "create", \ "entity": { \ "id": "Ke9nrZ4iRHWpKbJplG_zdQ", \ "type": "item", \ "attributes": { \ "text_field": "Test" \ }, \ "relationships": { \ "item_type": { \ "data": { \ "id": "Dq4WEbdjStWIeSeH_lBA-Q", \ "type": "item_type" \ } \ }, \ "creator": { \ "data": { \ "id": "104280", \ "type": "account" \ } \ } \ }, \ "meta": { \ "created_at": "2024-04-03T22:47:43.488+01:00", \ "updated_at": "2024-04-03T22:47:43.496+01:00", \ "published_at": "2024-04-03T22:47:43.532+01:00", \ "publication_scheduled_at": null, \ "unpublishing_scheduled_at": null, \ "first_published_at": "2024-04-03T22:47:43.532+01:00", \ "is_valid": true, \ "is_current_version_valid": true, \ "is_published_version_valid": true, \ "status": "published", \ "current_version": "QXuPXVc6SDmXcDh1MnImHQ", \ "stage": null \ } \ }, \ "related_entities": [ \ { \ "id": "Dq4WEbdjStWIeSeH_lBA-Q", \ "type": "item_type", \ "attributes": { \ "name": "Example Model", \ "singleton": true, \ "sortable": false, \ "api_key": "example_model", \ "ordering_direction": null, \ "ordering_meta": null, \ "tree": false, \ "modular_block": false, \ "draft_mode_active": false, \ "all_locales_required": false, \ "collection_appearance": "table", \ "has_singleton_item": true, \ "hint": null, \ "inverse_relationships_enabled": false \ }, \ "relationships": { \ "fields": { \ "data": [ \ { \ "id": "TuzswqxpQXyzJGv_3JtBAA", \ "type": "field" \ } \ ] \ }, \ "fieldsets": { \ "data": [] \ }, \ "singleton_item": { \ "data": { \ "id": "Ke9nrZ4iRHWpKbJplG_zdQ", \ "type": "item" \ } \ }, \ "ordering_field": { \ "data": null \ }, \ "title_field": { \ "data": { \ "id": "TuzswqxpQXyzJGv_3JtBAA", \ "type": "field" \ } \ }, \ "image_preview_field": { \ "data": null \ }, \ "excerpt_field": { \ "data": null \ }, \ "workflow": { \ "data": null \ } \ }, \ "meta": { \ "has_singleton_item": true \ } \ } \ ] \ }', request_headers: { Accept: "*/*", "X-Site-Id": "128378", "User-Agent": "DatoCMS (datocms.com)", "Content-Type": "application/json", "X-Webhook-Id": "27321", "X-Environment": "main", }, response_status: 200, response_headers: { date: "Wed, 03 Apr 2024 21:47:44 GMT", "content-length": "2", }, created_at: "2024-04-03T21:47:44.093Z", response_payload: "OK", entity_type: "item", event_type: "create", webhook: { id: "27321", type: "webhook" }, }, // etc]
The webhookCalls.list()
method does NOT support serverside filtering.
If you wish to filter the calls by some payload attribute, you must fetch them from the server and then filter them clientside, after decoding their request_payload
fields with JSON.parse()
.
This example shows how to filter the calls by their environment names.
import { buildClient } from "@datocms/cma-client-node";
async function run() { // Make sure the API token has access to the CMA, and is stored securely const client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });
// Which environment to look for const environmentNameToFilterBy = "main";
// Because we can't filter serverside, we'll have to fetch all the calls and then deal with them clientside const iterator = await client.webhookCalls.listPagedIterator();
// Empty array will be filled by the iterator let filteredWebhookCalls = [];
// Go through the async iterable one at a time for await (const call of iterator) { // Parse the stringified webhook payload const payload = JSON.parse(call.request_payload);
// Only push to the array if the environment matches const environment = payload.environment; if (environment === environmentNameToFilterBy) { filteredWebhookCalls.push(call); } }
console.log(filteredWebhookCalls);}
run();
[ { id: "84033321", type: "webhook_call", request_url: "https://www.example.com/webhook", request_payload: '{ \ "environment": "main", \ "entity_type": "item", \ "event_type": "create", \ "entity": { \ "id": "Ke9nrZ4iRHWpKbJplG_zdQ", \ "type": "item", \ "attributes": { \ "text_field": "Test" \ }, \ "relationships": { \ "item_type": { \ "data": { \ "id": "Dq4WEbdjStWIeSeH_lBA-Q", \ "type": "item_type" \ } \ }, \ "creator": { \ "data": { \ "id": "104280", \ "type": "account" \ } \ } \ }, \ "meta": { \ "created_at": "2024-04-03T22:47:43.488+01:00", \ "updated_at": "2024-04-03T22:47:43.496+01:00", \ "published_at": "2024-04-03T22:47:43.532+01:00", \ "publication_scheduled_at": null, \ "unpublishing_scheduled_at": null, \ "first_published_at": "2024-04-03T22:47:43.532+01:00", \ "is_valid": true, \ "is_current_version_valid": true, \ "is_published_version_valid": true, \ "status": "published", \ "current_version": "QXuPXVc6SDmXcDh1MnImHQ", \ "stage": null \ } \ }, \ "related_entities": [ \ { \ "id": "Dq4WEbdjStWIeSeH_lBA-Q", \ "type": "item_type", \ "attributes": { \ "name": "Example Model", \ "singleton": true, \ "sortable": false, \ "api_key": "example_model", \ "ordering_direction": null, \ "ordering_meta": null, \ "tree": false, \ "modular_block": false, \ "draft_mode_active": false, \ "all_locales_required": false, \ "collection_appearance": "table", \ "has_singleton_item": true, \ "hint": null, \ "inverse_relationships_enabled": false \ }, \ "relationships": { \ "fields": { \ "data": [ \ { \ "id": "TuzswqxpQXyzJGv_3JtBAA", \ "type": "field" \ } \ ] \ }, \ "fieldsets": { \ "data": [] \ }, \ "singleton_item": { \ "data": { \ "id": "Ke9nrZ4iRHWpKbJplG_zdQ", \ "type": "item" \ } \ }, \ "ordering_field": { \ "data": null \ }, \ "title_field": { \ "data": { \ "id": "TuzswqxpQXyzJGv_3JtBAA", \ "type": "field" \ } \ }, \ "image_preview_field": { \ "data": null \ }, \ "excerpt_field": { \ "data": null \ }, \ "workflow": { \ "data": null \ } \ }, \ "meta": { \ "has_singleton_item": true \ } \ } \ ] \ }', request_headers: { Accept: "*/*", "X-Site-Id": "128378", "User-Agent": "DatoCMS (datocms.com)", "Content-Type": "application/json", "X-Webhook-Id": "27321", "X-Environment": "main", }, response_status: 200, response_headers: { date: "Wed, 03 Apr 2024 21:47:44 GMT", "content-length": "2", }, created_at: "2024-04-03T21:47:44.093Z", response_payload: "OK", entity_type: "item", event_type: "create", webhook: { id: "27321", type: "webhook" }, }, // other calls filtered out, so only this one remains]