> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Data ingestion

> Push your supply-chain data into InsightChain's canonical model, safely and repeatably.

The ingest endpoint is idempotent (safe to re-run), validates every record against a schema, upserts by `external_id`, and returns per-entity counts. Authenticate with an API key that has the `ingest` scope. A request carries at most 1,000 records across all entities in a body of up to 2 MB; send larger loads as several batches.

```text theme={null}
POST /v1/ingest/records
Authorization: Bearer YOUR_INGEST_API_KEY
Content-Type: application/json
```

## Canonical entities

`suppliers`, `items`, `item_variants` (sizes and options), `product_lots` (batches and expiry), `locations`, `customers`, `inventory_levels`, `purchase_orders`, `goods_receipts`, `sales_orders`. Each entity is an array of records keyed by `external_id`.

A goods receipt is one received line against a purchase order line: its own `external_id`, the `document_external_id` of the receipt document it belongs to, `po_external_id` and `po_line_number`, a signed `quantity` and a `posting_date`, all required. When a PO line has receipts, its received quantity is their sum, which drives open-PO quantities.

Request: an item, a location and its stock.

```bash theme={null}
curl -X POST "https://api.insightchain.ai/v1/ingest/records" \
  -H "Authorization: Bearer YOUR_INGEST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "connection": "erp-prod",
    "entities": {
      "items": [
        { "external_id": "MAT-1", "description": "Classic Polo", "uom": "EA", "unit_cost": 18.5 }
      ],
      "locations": [
        { "external_id": "DC-East", "name": "East distribution centre", "location_type": "distribution_center" }
      ],
      "inventory_levels": [
        { "item_external_id": "MAT-1", "location_external_id": "DC-East", "quantity_on_hand": 420 }
      ]
    }
  }'
```

Response: `200 OK` (abridged: `results` lists every entity, sent or not).

```json theme={null}
{
  "request_id": "…",
  "run_id": "…",
  "connection": "erp-prod",
  "status": "success",
  "results": {
    "items": { "received": 1, "upserted": 1, "failed": 0 },
    "locations": { "received": 1, "upserted": 1, "failed": 0 },
    "inventory_levels": { "received": 1, "upserted": 1, "failed": 0 }
  },
  "error_count": 0,
  "errors": [],
  "duration_ms": 412
}
```

At most 50 record errors are returned in `errors`; `error_count` is the full number.

## Retries: Idempotency-Key

Send an `Idempotency-Key` header (1 to 128 visible ASCII characters, a UUID for example) to retry a push safely. Keys are scoped to your organization, and a key belongs to the exact bytes of the body it was first sent with: re-send the same bytes, not a re-serialized copy. Sending the key again gives:

| Answer | Code or field | When |
| - | - | - |
| `200` replay | `replayed: true` | The earlier push finished (status `success` or `partial`): its recorded answer, with its `original_request_id`. Nothing is processed again. |
| `200` retry | processed again | The earlier push failed (a 500, or status `failed`), or is still marked in progress more than 10 minutes after it started: it is processed again under the same key, as a new run. |
| `409` | `idempotency_key_in_use` | The earlier push is still being processed (started less than 10 minutes ago). Retry after the `Retry-After` header's seconds. |
| `422` | `idempotency_key_reused` | The key was already used with a different request body. Use a new key for a new body. |

Records are upserts by `external_id`, so a push processed twice lands the same data; the key keeps retry logic clean, it is not what keeps the data safe.

The rules for every other `POST` are under [Conventions](/docs/conventions.md#idempotency-key).

## The other ingest routes

Beside the canonical records:

| Method | Path | What it takes |
| - | - | - |
| `POST` | `/v1/ingest/sensor_events` | Sensor reads: RFID, ambient IoT, temperature and GPS, up to 1,000 per call |
| `POST` | `/v1/ingest/supplier_invoices` | Supplier invoices, up to 500 per call |
| `POST` | `/v1/ingest/competitor_data` | Your own competitor data: brands, styles and trend signals |

Each takes the `ingest` scope and an API key, and its module is enabled per organization.

One competitor call takes at most 1,000 brands, 5,000 styles and 10,000 signals in a body of up to 4 MB (larger answers `413`); the whole body is checked before anything is written, so one bad record answers `400` with every field error in `details` and writes nothing.

For sensor events and supplier invoices, at most the first 50 rejected records are listed in `errors`; `error_count` is the full number.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.