First, if I call buildClient with the environment property, it does not seem to get applied when I call webhookCalls.list() or webhookCalls.rawList(). Is that expected? Is it because webhooks arenāt specific to environments (generally speaking) and thus their artifacts and history arenāt either?
Second, in the Pagination docs (Pagination ā DatoCMS), I see an example of passing page[limit] and page[offset] via curl but not via js/ts using listPagedIterator, which is what I think I need to use. What does an example of that look like?
Third, is the filter example as shown in the Pagination docs generally applicable for client.webhookCalls.listPagedIterator()? Can I pass multiple filter criteria? Examples of that?
In general, API access to the webhook call history is underdocumented. Another example of that is that I had to figure out on my own that the āfull accessā API token must be used. It would be helpful if that documentation could be fleshed out with examples, a list of all the functions and options to the functions on the client.webhookCalls object, etc.
Note that the request_payload.environment property does not match ādevelopmentā.
To investigate further, I simplified the filter, closer to the example on the āPaginationā docs:
for await (const webhookCall of client.webhookCalls.listPagedIterator({ filter: { type: 'NOT-webhook_call' }})) {
That still returns the type: 'webhook_call' entries. I would expect with that filter that nothing would be returned from webhookCalls.listPagedIterator(), but itās still returning entries.
Is filter not implemented for webhookCalls.listPagedIterator()? How about the page[limit] and page[offset] options?
I could really use some guidance. Iām sort of stuck on how to proceed.
Sorry for the confusion here! Iāll try to answer your questions one by oneā¦
Webhooks are project-wide, but they can be limited to a specific environment as a trigger condition
Webhook calls, both via the API or when you manually look at them in the UI (under āWebhooks activityā, https://yourproje.admin.datocms.com/project_settings/webhook_calls), should show an environment property. Sorry, this was an error in our CMA docs that Iāll update shortly!
For pagination, please see List all records - Record - Content Management API under the āFetching all pagesā header for a better example. (Basically, you start with an empty array and use the iterator to push to it one entry at a time). Iāll also update the Pagination docs page with a better example.
Sorry, the webcallCalls endpoint/JS method doesnāt support server-side filtering. You can filter it clientside after downloading all of them, with something like:
In general, API access to the webhook call history is underdocumented
Yes, sorry, this is something weāre working through as quickly as we can! We just overhauled the records section recently, and are working our way down the list. Some of it is auto-generated (like the accepted query parameters), so you can look at that part. But weāre trying to add better examples across the board to make it all clearer.
In the meantime, if you ever have a question about something, please feel free to ask and weāll prioritize answering you (I know you shouldnāt have to do this, and hopefully soon you wonāt, once we can refresh all the docs!)
That applies to list(), but listPagedIterator() will get you everything, even if you pass it a page parameter ā I think that part is a bug (it shouldnāt accept those query parameters because they do nothing). Iāll report it.
TLDR to put this all together, this is how you filter webhook calls by environment:
const webhookCalls = await client.webhookCalls.listPagedIterator();
let allCalls = []
for await (const webhookCall of webhookCalls) {
allCalls.push(webhookCall);
}
const filteredCalls = allCalls.filter(call => {
const payload = JSON.parse(call.request_payload);
return payload['environment'] === 'main'
})
console.log(`There are ${allCalls.length} calls total, and ${filteredCalls.length} of those match the environment.`);
// Returns "There are 4 calls total, and 2 of those match the environment."
Sorry again for the confusion here. Weāll update the docs as soon as we can.