Batch requests API
Up to 100 GET requests in one call; each result is a full envelope, charged as if called alone (cached repeats and failures free).
POST /v1/batch
POST /v1/batch
Up to 100 GET requests in one call; each result is a full envelope, charged as if called alone (cached repeats and failures free). Items run concurrently, each counts toward the rate limit, and a failed item never fails the others. Send an Idempotency-Key header to retry a batch safely: the first answer is replayed and nothing is charged twice.
- Cost: The sum of each sub-request's charge
- Cache: Not cached.
- Timeout: A request still running after about 25 seconds answers
202with a job to poll (Batch and jobs).
Parameters#
| Name | Type | Required | Description | In |
|---|---|---|---|---|
requests | array | yes | List of {"path": "/v1/...", "params": {...}}. | body |
Example request#
Set your key in the environment first (see Authentication).
1curl -X POST "https://api.socialscrape.dev/v1/batch" \2 -H "x-api-key: $SOCIALSCRAPE_API_KEY" \3 -H "content-type: application/json" \4 -d '{"requests":[{"path":"/v1/github/user","params":{"handle":"torvalds"}},{"path":"/v1/github/user","params":{"handle":"gaearon"}}]}'1import os2import requests34payload = {5 "requests": [6 {7 "path": "/v1/github/user",8 "params": {9 "handle": "torvalds",10 },11 },12 {13 "path": "/v1/github/user",14 "params": {15 "handle": "gaearon",16 },17 },18 ],19}20res = requests.post(21 "https://api.socialscrape.dev/v1/batch",22 headers={"x-api-key": os.environ["SOCIALSCRAPE_API_KEY"]},23 json=payload,24)25body = res.json()2627if body["ok"]:28 print(body["data"])29else:30 print(body["error"]["code"], body["error"]["message"])1const res = await fetch("https://api.socialscrape.dev/v1/batch", {2 method: "POST",3 headers: { "x-api-key": process.env.SOCIALSCRAPE_API_KEY!, "content-type": "application/json" },4 body: JSON.stringify({"requests": [{"path": "/v1/github/user", "params": {"handle": "torvalds"}}, {"path": "/v1/github/user", "params": {"handle": "gaearon"}}]}),5});6const body = await res.json();78if (body.ok) {9 console.log(body.data);10} else {11 console.error(body.error.code, body.error.message);12}Example response#
This is a sample with illustrative values. Status 200.
1{2 "ok": true,3 "credits_charged": 2,4 "credits_remaining": 4998,5 "cached": false,6 "cached_at": null,7 "request_id": "req_48cebd0a43eb45183d397192",8 "data": {9 "object": "batch",10 "results": [11 {12 "path": "/v1/github/user",13 "status": 200,14 "response": {15 "ok": true,16 "credits_charged": 1,17 "credits_remaining": 4999,18 "cached": false,19 "cached_at": null,20 "request_id": "req_a1b2c3d4e5f6a1b2c3d4e5f6",21 "data": {22 "object": "profile",23 "platform": "github",24 "id": "1024025",25 "handle": "torvalds",26 "name": "Linus Torvalds",27 "url": "https://github.com/torvalds",28 "kind": "person"29 },30 "cursor": null,31 "has_more": null32 }33 },34 {35 "path": "/v1/github/user",36 "status": 200,37 "response": {38 "ok": true,39 "credits_charged": 1,40 "credits_remaining": 4998,41 "cached": false,42 "cached_at": null,43 "request_id": "req_f6e5d4c3b2a1f6e5d4c3b2a1",44 "data": {45 "object": "profile",46 "platform": "github",47 "id": "810438",48 "handle": "gaearon",49 "name": "Dan Abramov",50 "url": "https://github.com/gaearon",51 "kind": "person"52 },53 "cursor": null,54 "has_more": null55 }56 }57 ]58 },59 "cursor": null,60 "has_more": null61}Response#
A BatchResult object in data.
See Data models for every field. The envelope around data is described in Responses.
Errors#
Failures are free: credits_charged is 0. Branch on error.code, never on the message.
| Code | HTTP | Retry | Meaning |
|---|---|---|---|
invalid_params | 400 | no | A parameter is missing, unknown or has the wrong type. |
Every request can also fail with the account and platform errors listed on the Errors page.