Write the API client
Every request carries the token in an Authorization: Bearer header. The sandbox is sandbox-api-shipx-pl.easypack24.net, production api-shipx-pl.easypack24.net. The X-User-Agent header is optional and helps InPost diagnose when you report a problem.
const API = process.env.SHIPX_URL ?? 'https://sandbox-api-shipx-pl.easypack24.net';const TOKEN = process.env.SHIPX_TOKEN ?? '';const ORG = process.env.SHIPX_ORG ?? '';export async function shipx<T>(method: string, path: string, body?: unknown): Promise<T> { const response = await fetch(`${API}${path}`, { method, headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json', 'X-User-Agent': 'shop-example', }, body: body === undefined ? undefined : JSON.stringify(body), }); if (!response.ok) { throw new Error(`ShipX ${method} ${path}: ${response.status} ${await response.text()}`); } return response.json() as Promise<T>;}