Errors

Every error has the same shape, a stable code you can branch on, a message you can show to people, and a flag that says whether trying again can help.

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.

An error response
{
  "success": false,
  "error": {
    "code": "rate_limited",
    "message": "Rate limit of 180 requests per minute exceeded",
    "retryable": true
  },
  "requestId": "req_V2m8xQ1kLp0aZ3"
}

Error codes

CodeHTTP statusWhat it means
bad_request400The request is malformed: invalid JSON, an unknown platform, a time in the past, or a method the endpoint does not accept (405).
unauthorized401No API key, or the key is invalid, revoked or expired.
insufficient_credits402The workspace, or the key's own budget, does not have enough credits. details has required and remaining.
plan_limit402The plan does not include this, or a plan limit (channels, API keys, automations, monitors) is reached.
forbidden403The key is missing a scope, may not post to this network, or the action needs a dashboard session. For team members, the role does not allow it.
not_found404The resource or endpoint does not exist in this workspace.
content_unavailable404The public content you asked to scrape is private, deleted or not available.
conflict409The resource is in the wrong state, for example editing a published post, or a short link name is taken.
validation_error422The input does not match the schema, or a post fails validation for a network. See below.
unsupported400The operation does not exist for this kind of link or network.
rate_limited429Too many requests. Wait for Retry-After seconds.
internal_error500Something failed on our side. Retry, and contact support with the request id if it continues.
platform_error502The social network returned an error or did not answer. Often retryable.
not_configured503This server is missing the app keys or tools for the feature, for example a network's OAuth app.

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.

422 validation_error
{
  "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})`);
}

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.