There are 2 methods for handling your API requests:
- Direct (Synchronous) requests - send a request and get the response in real-time
- Asynchronous requests - send requests without waiting for the responses, and get 'response IDs'. We will store the responses for 24 hours from the time the request was sent. You can collect the responses at your convenience via API command or Webhook.
Therefore, Asynchronous requests require 2 separate API commands:
- Sending the request - this request includes the search parameters, will return a response_ID and will be charged as a direct request (i.e. this is the request to be billed for).
- Collecting the response - this request includes the response_ID, and it is free of charge (i.e. will not be billed for).
Sending an Asynchronous request - API command - curl example
curl -i --silent --compressed "https://brightdata.com/api/serp/req?customer=[ACCOUNT_ID]&zone=[ZONE_NAME]" -H "Content-Type: application/json" -H "Authorization: Bearer [API_TOKEN]" -d "{\"country\":\"us\",\"query\":{\"q\":\"pizza\",\"num\":\"100\",\"hl\":\"en\",\"gl\":\"au\"}}"
`x-response-id` header will contain the ID of the request. Use it in the collection request
Collecting an Asynchronous response - API command - curl example
curl -v --compressed "https://brightdata.com/api/serp/get_result?customer=[ACCOUNT_ID]&zone=[ZONE_NAME]&response_id=${[RESPONSE_ID]}" -H "Authorization: Bearer [API_TOKEN]"
Notes:
- Asynchronous mode is recommended for high-volume requests
- When asynchronous requests is enabled on a Search Engine Crawler zone's settings, the API generated on the API playground and on the API Guide will adjust accordingly
For more information, read the following: Configure a Search Engine Crawler zone