Parameters to control offset-based pagination
Attributes to filter
Fields used to order results
import { buildClient } from "@datocms/cma-client-node";async function run() {// Make sure the API token has access to the CMA, and is stored securelyconst client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });const webhookCalls = await client.webhookCalls.list();console.log(webhookCalls);}run();
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 securelyconst client = buildClient({ apiToken: process.env.DATOCMS_API_TOKEN });// Which environment to look forconst environmentNameToFilterBy = "main";// Because we can't filter serverside, we'll have to fetch all the calls and then deal with them clientsideconst iterator = await client.webhookCalls.listPagedIterator();// Empty array will be filled by the iteratorlet filteredWebhookCalls = [];// Go through the async iterable one at a timefor await (const call of iterator) {// Parse the stringified webhook payloadconst payload = JSON.parse(call.request_payload);// Only push to the array if the environment matchesconst environment = payload.environment;if (environment === environmentNameToFilterBy) {filteredWebhookCalls.push(call);}}console.log(filteredWebhookCalls);}run();