Box’a’Fox

Code examples

The API and the gateway from curl, Python and Node.js.

The examples read two secrets from the environment: BOXAFOX_KEY (an API key) and BOXAFOX_PROXY_PASSWORD (a proxy user's password).

Call the API

curl https://api.boxafox.com/v1/residential/summary \
  -H "X-API-Key: $BOXAFOX_KEY"

Handle errors

Branch on the error code and keep the request_id:

r = api.post("https://api.boxafox.com/v1/proxy-users", json={"username": "acme_scraper1"})
if r.status_code == 409 and r.json()["error"] == "username_taken":
    ...  # pick another name
elif not r.ok:
    body = r.json()
    raise RuntimeError(f'{body["error"]} ({body["request_id"]})')

Buy data safely

Generate the Idempotency-Key once and reuse it on every retry of the same purchase:

import uuid

key = str(uuid.uuid4())
order = api.post(
    "https://api.boxafox.com/v1/checkout",
    headers={"Idempotency-Key": key},
    json={"items": [{"product_code": "mobile_gb", "gb": 2}]},
)

Send traffic through the gateway

curl -x "http://acme_net_res_c_de:$BOXAFOX_PROXY_PASSWORD@gw.boxafox.com:8000" \
  https://ipinfo.io/json

When the gateway refuses a connection, the reason is in the X-Proxy-Error response header: see Errors.

On this page