Last active
August 27, 2024 09:41
-
-
Save stefanoverna/05201c36cfd8f9e6bb7cf3913cbf1ae0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { buildClient } from "@datocms/cma-client-node"; | |
import fetch from "cross-fetch"; | |
const client = buildClient({ | |
apiToken: process.env.READWRITE_DATOCMS_API_TOKEN, | |
fetchFn: fetch, | |
}); | |
async function run() { | |
for await (const delivery of client.webhookCalls.listPagedIterator({ | |
filter: { | |
fields: { | |
// Affected deliveries are within this timerange | |
created_at: { | |
gt: "2024-08-26T14:02:51+02:00", | |
lt: "2024-08-27T09:52:25+02:00", | |
}, | |
status: { eq: "failed" }, | |
}, | |
}, | |
})) { | |
// Here you can access the delivery object (response status, headers, payloads, etc.) | |
// This is just an example that checks if the payload of the response contains a specific error: | |
if (delivery.response_payload?.includes('Missing authorization header')) { | |
// Resend the delivery if needed | |
await client.webhookCalls.resendWebhook(delivery.id); | |
} | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment