Lesson 03

Sending POST requests

Some endpoints only accept POST — search forms, GraphQL queries, JSON APIs. ScraperAPI forwards the body and Content-Type you send it straight through to the target URL.

How it works

Keep api_key and url as query parameters on https://api.scraperapi.com/, and put your payload in the request body. ScraperAPI forwards the body and the Content-Type header to the target URL, and returns the target's response back to you.

LocationTypePurpose
api_keyquery stringYour ScraperAPI key.
urlquery stringThe target endpoint that expects the POST.
Content-TypeheaderTells ScraperAPI (and the target) how to interpret your body.
request bodybodyThe payload the target endpoint expects.

Form-encoded body

For classic HTML forms and endpoints that read application/x-www-form-urlencoded bodies:

curl -X POST "https://api.scraperapi.com/?api_key=YOUR_API_KEY&url=https://httpbin.org/anything" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "name=ada&role=engineer"
import requests

r = requests.post(
    "https://api.scraperapi.com/",
    params={"api_key": "YOUR_API_KEY", "url": "https://httpbin.org/anything"},
    data={"name": "ada", "role": "engineer"},
    timeout=70,
)
print(r.text)
import axios from "axios";

const { data } = await axios.post(
  "https://api.scraperapi.com/",
  new URLSearchParams({ name: "ada", role: "engineer" }),
  {
    params: { api_key: "YOUR_API_KEY", url: "https://httpbin.org/anything" },
    headers: { "Content-Type": "application/x-www-form-urlencoded" },
  },
);
console.log(data);

JSON body

For JSON APIs, GraphQL endpoints, and anything expecting application/json:

curl -X POST "https://api.scraperapi.com/?api_key=YOUR_API_KEY&url=https://httpbin.org/anything" \
  -H "Content-Type: application/json" \
  -d '{"name":"ada","role":"engineer"}'
import requests

r = requests.post(
    "https://api.scraperapi.com/",
    params={"api_key": "YOUR_API_KEY", "url": "https://httpbin.org/anything"},
    json={"name": "ada", "role": "engineer"},
    timeout=70,
)
print(r.text)
import axios from "axios";

const { data } = await axios.post(
  "https://api.scraperapi.com/",
  { name: "ada", role: "engineer" },
  {
    params: { api_key: "YOUR_API_KEY", url: "https://httpbin.org/anything" },
    headers: { "Content-Type": "application/json" },
  },
);
console.log(data);
Content-Type matters
The target endpoint decides how to parse the body from the Content-Type header. If you send JSON but forget the header, many servers will reject the request as malformed. Set it explicitly on every POST.