Skip to main content
Scrapes, searches, answers, and maps return the result in the response. Batches and crawls are different. They run in the background, and the create request returns a job id right away.

How an async job works

  1. Create the job with POST /v1/batches or POST /v1/crawls. Save the id from the response.
  2. Wait for the job. Check GET /v1/batches/{batch_id} or GET /v1/crawls/{crawl_id} until status is completed.
  3. Get the results. List the items of the batch or the pages of the crawl. Then get the content of each result with its retrieve_id.
Steps 2 and 3 use the saved job ID. If your program stops, use that ID to check the status and get the results. A new create request can repeat work and use more credits.

What completed means

When status is completed, stop checking the job status and list the results. Batch content can take more time to become readable. If the API returns failed, stop waiting and keep the job ID for support. completed does not mean that every URL worked:
  • Batch: a completed batch can include failed URLs. List them with GET /v1/batches/{batch_id}/items?status=failed.
  • Crawl: a crawl can complete with 0 pages. Check pages_count. The pages response lists the URLs that failed in metadata.failed_urls.
  • Content: in the GET /v1/retrieve response, if size_exceeded is true, get the Markdown from markdown_hosted_url. If markdown_content and markdown_hosted_url are both empty just after the batch completes, try the same retrieve_id again later.

Wait with a time limit

The helper below waits 10 seconds between checks. It starts no new check after 30 minutes. It also stops on an HTTP error, for example 401 or 429. Stopping does not cancel the job: you can check it again later with its ID. Use Python 3.9 or later, or Node.js 18 or later. For Python, install Requests with python -m pip install requests. Set the OLOSTEP_API_KEY environment variable before you run the samples.
Give the helper the path of the job: batches/<batch_id> or crawls/<crawl_id>. To check the status one time from a terminal:

Get the results later with the job ID

This example uses a saved batch ID. It waits for the batch to complete. Then it lists the completed and failed items. Each list stops with an error after 1,000 pages without a last page. This is a limit in the sample, not in the API. Save the Python blocks as wait_for_job.py and get_results.py in the same folder. For Node.js, use waitForJob.mjs and getResults.mjs. Replace YOUR_BATCH_ID with your saved batch ID.
To run the samples, use python get_results.py or node getResults.mjs. To get the content of each result, send its retrieve_id to GET /v1/retrieve. For a crawl, see Crawls. Instead of polling, you can also set a webhook when you create the job. See Webhooks.

Next steps

Batches

Scrape a list of URLs in one job.

Crawls

Get the pages of a whole site.

Retrieve content

Get the content of a result with its retrieve_id.

Webhooks

Get a request when a job completes.