Idempotency and external_ref

Networks fail. A request can time out after IQCore already did the work, and your code cannot tell. Two tools make a retry safe: Idempotency-Key for a single request, and external_ref for a post.

Idempotency-Key

Send the header on every POST, PATCH and DELETE. It is optional, but every example in these docs sends it.

curl
curl -X POST "https://iqcore.ai/api/public/v1/posts" \
  -H "Authorization: Bearer $IQCORE_KEY" \
  -H "Idempotency-Key: shop-item-42-create" \
  -H "Content-Type: application/json" \
  -d '{"channel_ids": ["..."], "caption": "New in the shop", "scheduled_at": "2026-12-20T09:00:00Z"}'
JavaScript
const res = await fetch("https://iqcore.ai/api/public/v1/posts", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.IQCORE_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": "shop-item-42-create",
  },
  body: JSON.stringify({ channel_ids, caption: "New in the shop", scheduled_at }),
});
const replayed = res.headers.get("Idempotent-Replayed") === "true";
Python
import os
import requests

res = requests.post(
    "https://iqcore.ai/api/public/v1/posts",
    headers={
        "Authorization": f"Bearer {os.environ['IQCORE_KEY']}",
        "Idempotency-Key": "shop-item-42-create",
    },
    json={"channel_ids": channel_ids, "caption": "New in the shop", "scheduled_at": scheduled_at},
    timeout=30,
)
replayed = res.headers.get("Idempotent-Replayed") == "true"

Format

  • 1 to 100 characters.
  • Letters, digits and . _ : - only.
  • Any other value answers 400 idempotency_key_invalid.
  • A random UUID is a good key for a one-off call. For work you may repeat later (for example "create the post for item 42"), build the key from your own data.

What happens

Situation Answer
First use of the key The request runs.
Same key, same request, within 24 hours The stored answer again, with the header Idempotent-Replayed: true. Nothing runs a second time. The replay has a new X-Request-Id.
Same key, a different request 422 idempotency_key_reused.
Same key while the first request is still running 409 request_in_progress with Retry-After: 1. Wait and retry.

"The same request" means the same operation, path parameters, query, JSON body and organization. For file uploads the file itself counts (a different file with the same key is idempotency_key_reused).

What is stored

  • Keys live for 24 hours and are bound to the API key that sent them. A different key never sees them.
  • A successful answer (2xx, except 202) and every server error (5xx) are stored. Replaying a 5xx gives you the same 5xx; use a new key to try the work again if you are sure it did not happen.
  • A refusal is not stored: 400, 401, 402, 403, 404, 409, 422, 429. Fix the cause and retry with the same key.
  • A 202 (a person must act first) frees the key too. After the person approved, you can send the same call again.
  • Reads ignore the header.

external_ref

external_ref is your own id for a post, for example the id of the product or the row in your database. It protects you across days, where an idempotency key has expired.

  • Send it in POST /posts. It is 1 to 191 printable ASCII characters, with no spaces.
  • It is unique per organization, and separately for test keys (sandbox) and live keys. A test key can reuse a reference a live key already used.
  • Creating a second post with an existing external_ref answers 409 external_ref_exists and gives the existing_id of the first.
  • Find a post by it: GET /posts?external_ref=shop:item:42.
json
{
  "error": {
    "type": "conflict",
    "code": "external_ref_exists",
    "message": "A post with this external_ref already exists.",
    "param": "external_ref",
    "request_id": "req_a1b2c3d4e5f6a1b2c3d4e5f6",
    "doc_url": "https://iqcore.ai/developers/docs/errors#external_ref_exists",
    "existing_id": "0d9c2d9a-1e8b-4b1e-9a77-2f1c4c3a8e55"
  }
}

A good pattern: create with external_ref. On 409, read existing_id and continue with that post instead of failing.

Next: Pagination, Post states and approval.