Callbacks

Using a status URL is a great way to test the API or get started quickly, but some customer environments may require some more robust solutions, so we implemented callbacks. Currently only webhook callbacks are supported but we are planning to introduce more over time (e.g. direct database callbacks, AWS S3, etc).

An example of using a webhook callback:

import requests

r = requests.post(url = 'https://async.scraperapi.com/jobs', json={ 'apiKey': 'xxxxxx', 'url': 'https://example.com', 'callback': {'type': 'webhook', 'url': 'https://yourcompany.com/scraperapi' }})
print(r.text)

Using a callback you donโ€™t need to use the status URL (although you still can) to fetch the status and results of the job. Once the job is finished the provided webhook URL will be invoked by our system with the same content as the status URL provides.

Just replace the https://yourcompany.com/scraperapi URL with your preferred endpoint. You can even add basic auth to the URL in the following format: https://user:pass@yourcompany.com/scraperapi

Note: The system will try to invoke the webhook URL 3 times, then it cancels the job. So please make sure that the webhook URL is available through the public internet and will be capable of handling the traffic that you need.

Hint: Webhook.site is a free online service to test webhooks without requiring you to build a complex infrastructure.

Last updated