Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Making A Request

This guide shows how to send your first request, read the response, and handle errors.

Before You Start

You need two things:

  • Credits on your Web Scraper API balance

  • Your API token, which you can find in the IPRoyal dashboard on the 'Web Scraper API' page

Store the token in an environment variable, such as WEB_SCRAPER_API_TOKEN. Never put it in browser code or a public repository. The examples below read it from that variable.

The Node.js examples need Node.js 18 or later and run as ES modules, so save them as .mjs files. The Java examples need Java 11 or later and use Jackson to read JSON. The C# examples are .NET 6 console apps.

Step 1: Send a Request

Send a POST request to https://scrape.iproyal.com/v1/scrape. Put your token in the Authorization header and the target in a JSON body.

curl -X POST https://scrape.iproyal.com/v1/scrape \
  -H "Authorization: Bearer $WEB_SCRAPER_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"source": "universal", "url": "https://example.com"}' \
  --max-time 90
<?php

$ch = curl_init('https://scrape.iproyal.com/v1/scrape');

curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 90,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('WEB_SCRAPER_API_TOKEN'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'source' => 'universal',
        'url' => 'https://example.com',
    ]),
]);

$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($status === 200) {
    $result = $body['results'][0];
    echo $result['status_code'] . ' ' . $result['job_id'] . PHP_EOL;
    $html = $result['content'];
} else {
    echo $status . ' ' . $body['error']['code'] . ': ' . $body['error']['message'] . PHP_EOL;
}

Step 2: Read the Response

A successful request returns HTTP 200:

The fields you use most:

  • content holds the scraped content. It is HTML for a web page, JSON for Google results or parsed pages, and a Base64 string for an image.

  • status_code is the HTTP status the target website returned. Check it before you use content. A 404 here means the target page does not exist.

  • job_id identifies the request. Keep it in your logs. IPRoyal Support can trace any request by its job_id.

Scraping describes every field.

Step 3: Choose What to Scrape

Change the request body to scrape something else.

A web page, seen from Germany

Structured data from a web page

Google search results

An image

Country Targeting

geo_location takes a two-letter country code in the ISO 3166-1 alpha-2 format, for example us, gb, de, fr, or jp. The target website then sees a visitor from that country. Use gb for the United Kingdom, not uk. Supported Countries lists every code you can use.

Without geo_location, IPRoyal selects the location automatically.

Step 4: Check Your Balance

User returns your credit balance:

Set a Timeout

Response time depends on the target website. Websites with strong anti-bot protection take longer. In rare cases, a request takes up to 75 seconds.

Set your HTTP client timeout to at least 90 seconds. If your client gives up earlier, the request can still finish on IPRoyal's side and use a credit.

Limits

Your account has a concurrency limit. It sets how many scrape requests can run at the same time.

User returns your limit in the concurrency_limit field.

When the limit is reached, a new scrape request returns 429 concurrency_limit_exceeded. The request is not charged. Retry after one of your running requests finishes.

503 capacity_exceeded is different. It means the whole service is at full capacity, regardless of your own limit.

To raise your concurrency limit, contact IPRoyal Support.

Handle Errors

Every error returns a JSON body with a stable code:

Follow these rules:

  • Branch on error.code, not on message. Messages can change.

  • Retry temporary errors with exponential backoff: concurrency_limit_exceeded, internal_error, upstream_unavailable, and capacity_exceeded.

  • Wait 2, 4, then 8 seconds between attempts, plus a short random delay. Stop after a few attempts.

  • Do not retry invalid_request, payload_too_large, invalid_token, insufficient_credit, account_suspended, or account_disabled without fixing the cause.

  • For blocked, retry later or with another geo_location. An immediate retry rarely helps.

IPRoyal already retries some temporary failures once before it responds. Requests that end in an error are not charged.

API lists every error code.

Retry Temporary Errors

These examples retry temporary errors with exponential backoff.

Last updated

Was this helpful?