RSHQ API V2 server examples

These examples send requests from your server. Set RSHQ_API_BASE to your configured HTTPS RSHQ API origin and keep the API key in a server-side environment variable.

Never put an API key in browser JavaScript, HTML, a URL, source control, or a client application. Use the availability shown on your signed-in API page. For a temporary service error, follow the response message and retain its request_id for support.

cURL — list services

curl --fail-with-body \
  -H "Authorization: Bearer ${RSHQ_API_KEY}" \
  -H "Accept: application/json" \
  "${RSHQ_API_BASE}/api/v2/services?page=1&page_size=25"

Python — create an order

import os
import uuid
import requests

base = os.environ["RSHQ_API_BASE"].rstrip("/")
key = os.environ["RSHQ_API_KEY"]
response = requests.post(
    f"{base}/api/v2/orders",
    headers={
        "Authorization": f"Bearer {key}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "service_id": "SERVICE_UUID_FROM_CATALOG",
        "quantity": 100,
        "currency": "USD",
        "input_data": {"link": "https://example.com/post"},
    },
    timeout=20,
)
response.raise_for_status()
print(response.json())

Persist the generated idempotency key with the operation and reuse it for retries of that same order intent. A successful response contains the RSHQ order id, charged currency and amount, status, and creation time.

Node.js — check balance

const base = process.env.RSHQ_API_BASE.replace(/\/+$/, "");
const response = await fetch(`${base}/api/v2/balance`, {
  headers: {
    Authorization: `Bearer ${process.env.RSHQ_API_KEY}`,
    Accept: "application/json",
  },
});
if (!response.ok) throw new Error(`RSHQ API returned ${response.status}`);
console.log(await response.json());

PHP — retrieve an order

<?php
$base = rtrim(getenv('RSHQ_API_BASE'), '/');
$key = getenv('RSHQ_API_KEY');
$orderId = 'ORDER_UUID';

$curl = curl_init($base . '/api/v2/orders/' . rawurlencode($orderId));
curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . $key,
        'Accept: application/json',
    ],
    CURLOPT_TIMEOUT => 20,
]);
$body = curl_exec($curl);
if ($body === false) {
    throw new RuntimeException(curl_error($curl));
}
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
if ($status < 200 || $status >= 300) {
    throw new RuntimeException('RSHQ API returned HTTP ' . $status);
}
var_dump(json_decode($body, true, flags: JSON_THROW_ON_ERROR));

Use only service and order IDs returned by the API. Prices are calculated by RSHQ; clients cannot set an order price. Do not automatically retry an uncertain supplier outcome with a new idempotency key.