id right away.
How an async job works
- Create the job with
POST /v1/batchesorPOST /v1/crawls. Save theidfrom the response. - Wait for the job. Check
GET /v1/batches/{batch_id}orGET /v1/crawls/{crawl_id}untilstatusiscompleted. - 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.
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 inmetadata.failed_urls. - Content: in the
GET /v1/retrieveresponse, ifsize_exceededistrue, get the Markdown frommarkdown_hosted_url. Ifmarkdown_contentandmarkdown_hosted_urlare both empty just after the batch completes, try the sameretrieve_idagain 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 example401 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.
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 aswait_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.
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.