Errors
Error shape
Errors return a 4xx or 5xx status with success: false. error.code is stable, error.message explains what happened and how to fix it, error.details carries structured extras, and error.retryable is true when the same request may work later. Quote the requestId (also in the X-Request-Id header) when you contact support.
{
"success": false,
"error": {
"code": "rate_limited",
"message": "Rate limit of 180 requests per minute exceeded",
"retryable": true
},
"requestId": "req_V2m8xQ1kLp0aZ3"
}Error codes
Validation errors
When the input does not match the schema, the status is 422 and details lists every problem with its path, message and code. The message names the first three.
{
"success": false,
"error": {
"code": "validation_error",
"message": "Invalid body: platforms Too small: expected array to have >=1 items",
"details": [
{
"path": "platforms",
"message": "Too small: expected array to have >=1 items",
"code": "too_small"
}
],
"retryable": false
},
"requestId": "req_9Kd2x..."
}When a post is valid JSON but breaks a network's rules (too long, too many images, a missing board), the status is also 422 and details.issues has the same per-platform list as POST /v1/posts/validate. See Posting.
Retrying
Retry when retryable is true or the status is 429, with a growing delay, and honor Retry-After. Do not retry other 4xx errors without changing the request.
async function call(path: string, init: RequestInit = {}, attempt = 0): Promise<any> {
const res = await fetch(`https://postkea.com/api${path}`, {
...init,
headers: { Authorization: `Bearer ${process.env.POSTKEA_API_KEY}`, "Content-Type": "application/json", ...init.headers },
});
const body = await res.json();
if (body.success) return body.data;
const { code, message, retryable } = body.error;
if ((retryable || res.status === 429) && attempt < 4) {
const wait = Number(res.headers.get("Retry-After") ?? 2 ** attempt);
await new Promise((r) => setTimeout(r, wait * 1000));
return call(path, init, attempt + 1);
}
throw new Error(`${code}: ${message} (${body.requestId})`);
}import os, time, requests
def call(method, path, attempt=0, **kwargs):
r = requests.request(
method,
f"https://postkea.com/api{path}",
headers={"Authorization": f"Bearer {os.environ['POSTKEA_API_KEY']}"},
**kwargs,
)
body = r.json()
if body["success"]:
return body["data"]
err = body["error"]
if (err.get("retryable") or r.status_code == 429) and attempt < 4:
time.sleep(float(r.headers.get("Retry-After", 2 ** attempt)))
return call(method, path, attempt + 1, **kwargs)
raise RuntimeError(f"{err['code']}: {err['message']} ({body['requestId']})")When you retry a request that creates something, send the same idempotencyKey so a post is never created twice.
Errors from social networks
A post that a network rejects does not fail the API request. The post is created, and the failed platform entry has status: failed with the network's error and an errorCode, for example reauth_required when the account must be reconnected. You receive post.failed or post.partial, and can fix the cause and retry just that platform. Background jobs report errors the same way, see Downloads and jobs.