Here’s an example Express.js handler for receiving webhook notifications:
Copy
app.post('/webhook/screenshots', (req, res) => { const { id, status, screenshotUrl, error } = req.body; if (status === 'completed') { console.log(`Screenshot ${id} ready at: ${screenshotUrl}`); // Save the URL, notify users, process the image, etc. } else if (status === 'failed') { console.error(`Screenshot ${id} failed: ${error}`); // Handle the failure, retry, or alert } // Respond with 200 to acknowledge receipt res.status(200).send('OK');});
Your webhook endpoint must respond with a 2xx status code within 10 seconds. If the endpoint fails or times out, Screenshotly may retry the notification.