Push-Pull is our recommended integration method for reliably handling large amounts of data.
Push-Pull is an asynchronous integration method. Upon job submission, you will promptly receive a JSON
response containing all job details, including job parameters, ID, and URLs for result download and status checking. Once your job is processed, we will update you via a JSON
payload sent to your server, if you provided a callback URL. Results remain available for retrieval for at least 24 hours after completion.
With Push-Pull, you can upload your results directly to your cloud storage (AWS S3 or Google Cloud Storage).
If you prefer not to set up a service for incoming callback notifications, you can simply retrieve your results periodically (polling ).
You can also explore how Push-Pull works using Postman .
Batch Query
Scraper APIs supports submitting up to 5,000 query
or url
parameter values within a single batch request.
Endpoint
Copy POST https://data.oxylabs.io/v1/queries/batch
The system will handle every query
or url
submitted as a separate job. If you provide a callback URL, you will get a separate call for each keyword. Otherwise, our initial response will contain job id
s for all keywords. For example, if you sent 50 keywords, we will return 50 unique job id
s.
IMPORTANT: With /batch
endpoint, you can only submit lists of query
or url
parameter values (depending on the source
you use). All other parameters should have singular values.
Input
You need to post query parameters as a JSON payload. Here is how you submit a batch job:
cURL Python PHP C# Golang Java Node.js
Copy curl --user "user:pass1" \
'https://data.oxylabs.io/v1/queries/batch' \
-H 'Content-Type: application/json' \
-d '@keywords.json'
Copy import requests
import json
from pprint import pprint
# Get payload from file.
with open ( 'keywords.json' , 'r' ) as f :
payload = json . loads (f. read ())
response = requests . request (
'POST' ,
'https://data.oxylabs.io/v1/queries/batch' ,
auth = ( 'user' , 'pass1' ),
json = payload,
)
# Print prettified response.
pprint (response. json ())
Copy <? php
$paramsFile = file_get_contents ( realpath ( "keywords.json" )) ;
$ch = curl_init () ;
curl_setopt ( $ch , CURLOPT_URL , "https://data.oxylabs.io/v1/queries/batch" ) ;
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ) ;
curl_setopt ( $ch , CURLOPT_POSTFIELDS , $paramsFile ) ;
curl_setopt ( $ch , CURLOPT_POST , 1 ) ;
curl_setopt ( $ch , CURLOPT_USERPWD , "user" . ":" . "pass1" ) ;
$headers = array ();
$headers[] = "Content-Type: application/json" ;
curl_setopt ( $ch , CURLOPT_HTTPHEADER , $headers ) ;
$result = curl_exec ( $ch ) ;
echo $result;
if ( curl_errno ( $ch ) ) {
echo 'Error:' . curl_error ( $ch ) ;
}
curl_close ( $ch ) ;
?>
Copy using System ;
using System . IO ;
using System . Net . Http ;
using System . Text ;
using System . Threading . Tasks ;
namespace OxyApi
{
class Program
{
static async Task Main ()
{
const string Username = "YOUR_USERNAME" ;
const string Password = "YOUR_PASSWORD" ;
var content = File . ReadAllText ( @"C:\path\to\keywords.json" );
var client = new HttpClient ();
var requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri("https://data.oxylabs.io/v1/queries/batch"));
requestMessage . Content = new StringContent (content , Encoding . UTF8 , "application/json" );
var authenticationString = $"{Username}:{Password}" ;
var base64EncodedAuthenticationString = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(authenticationString));
requestMessage . Headers . Add ( "Authorization" , "Basic " + base64EncodedAuthenticationString);
var response = await client . SendAsync (requestMessage);
var contents = await response . Content . ReadAsStringAsync ();
Console . WriteLine (contents);
}
}
}
Copy package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main () {
const Username = "YOUR_USERNAME"
const Password = "YOUR_PASSWORD"
content, err := os.ReadFile( "keywords.json" )
if err != nil {
panic (err)
}
client := & http . Client {}
request, _ := http.NewRequest( "POST" ,
"https://data.oxylabs.io/v1/queries/batch" ,
bytes.NewBuffer(content),
)
request.Header.Add( "Content-type" , "application/json" )
request.SetBasicAuth(Username, Password)
response, _ := client.Do(request)
responseText, _ := ioutil.ReadAll(response.Body)
fmt.Println( string (responseText))
}
Copy import okhttp3 . * ;
import java . io . IOException ;
import java . nio . file . Files ;
import java . nio . file . Path ;
public class Main implements Runnable {
private static final String AUTHORIZATION_HEADER = "Authorization" ;
public static final String USERNAME = "YOUR_USERNAME" ;
public static final String PASSWORD = "YOUR_PASSWORD" ;
public void run () {
Path filePath = Path . of ( "/path/to/keywords.json" );
String jsonContent = null ;
try {
jsonContent = Files . readString (filePath);
} catch ( IOException e) {
throw new RuntimeException(e) ;
}
Authenticator authenticator = (route , response) -> {
String credential = Credentials . basic (USERNAME , PASSWORD);
return response
. request ()
. newBuilder ()
. header (AUTHORIZATION_HEADER , credential)
. build ();
};
var client = new OkHttpClient . Builder ()
. authenticator (authenticator)
. build ();
var mediaType = MediaType . parse ( "application/json; charset=utf-8" );
var body = RequestBody . create (jsonContent , mediaType);
var request = new Request . Builder ()
. url ( "https://data.oxylabs.io/v1/queries/batch" )
. post (body)
. build ();
try ( var response = client . newCall (request) . execute ()) {
assert response . body () != null ;
System . out . println ( response . body () . string ());
} catch ( Exception exception) {
System . out . println ( "Error: " + exception . getMessage ());
}
System . exit ( 0 );
}
public static void main ( String [] args) {
new Thread( new Main()) . start ();
}
}
Copy import fetch from 'node-fetch' ;
import fs from 'fs'
const username = 'YOUR_USERNAME' ;
const password = 'YOUR_PASSWORD' ;
const payload = fs.readFileSync ( 'keywords.json' ) .toString ();
const response = await fetch ( 'https://data.oxylabs.io/v1/queries/batch' , {
method: 'post' ,
body: payload,
headers: {
'Content-Type' : 'application/json' ,
'Authorization' : 'Basic ' + Buffer.from ( `${username}:${password}` ) .toString ( 'base64' ) ,
}
});
console.log(await response.json ());
You may notice that the code example above doesn't explain how the JSON payload should be formatted and points out to a pre-made JSON file. Below is the content of keywords.json
file, containing multiple query
parameter values:
Copy {
"query" : [
"adidas" ,
"nike" ,
"reebok"
] ,
"source" : "google_shopping_search" ,
"domain" : "com" ,
"callback_url" : "https://your.callback.url"
}
...and here is a keywords.json
batch input file, containing multiple URLs:
Copy {
"url" : [
"https://example.com/url1.html" ,
"https://example.com/url2.html" ,
"https://example.com/url3.html"
] ,
"source" : "universal" ,
"callback_url" : "https://your.callback.url"
}
Output
The API will respond with a JSON object, containing the job information for each job created. The response will be similar to this:
Copy {
"queries" : [
{
"callback_url" : "https://your.callback.url" ,
{...}
"created_at" : "2024-06-26 00:00:01" ,
"domain" : "com" ,
"id" : "12345678900987654321" ,
{...}
"query" : "adidas" ,
"source" : "google_shopping_search" ,
{...}
"rel" : "results" ,
"href" : "http://data.oxylabs.io/v1/queries/12345678900987654321/results" ,
"method" : "GET"
}
]
},
{
"callback_url" : "https://your.callback.url" ,
{...}
"created_at" : "2024-06-26 00:00:01" ,
"domain" : "com" ,
"id" : "12345678901234567890" ,
{...}
"query" : "nike" ,
"source" : "google_shopping_search" ,
{...}
"rel" : "results" ,
"href" : "http://data.oxylabs.io/v1/queries/12345678901234567890/results" ,
"method" : "GET"
}
]
},
{
"callback_url" : "https://your.callback.url" ,
{...}
"created_at" : "2024-06-26 00:00:01" ,
"domain" : "com" ,
"id" : "01234567899876543210" ,
{...}
"query" : "reebok" ,
"source" : "google_shopping_search" ,
{...}
"rel" : "results" ,
"href" : "http://data.oxylabs.io/v1/queries/01234567899876543210/results" ,
"method" : "GET"
}
]
}
]
}
Last updated 3 months ago