---
title: Orders
description: Send the orders of your shop with POST /v1/orders, and send an order again when it changes.
---

Send each order of your shop to Optifeed. Optifeed calculates the RFM segments of your customers from the orders. When an order changes, for example after a refund, send the full order again.

## Send orders

`POST https://api.optifeed.com/v1/orders`

Send a JSON object with an `orders` list of 1 to 1,000 orders.

```bash
curl https://api.optifeed.com/v1/orders \
  -H "Authorization: Bearer $OPTIFEED_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "orders": [
      {
        "id": "A-1",
        "created_at": "2026-11-20T14:05:00+03:00",
        "updated_at": "2026-11-20T14:05:00+03:00",
        "currency": "TRY",
        "subtotal": "180.00",
        "discount": "10.00",
        "tax": "20.00",
        "shipping": "9.90",
        "total": "199.90",
        "financial_status": "paid",
        "fulfillment_status": "fulfilled",
        "customer": {
          "id": "C-9",
          "email_sha256": "9b00b0b820caf9556ca074ae455f87d32be94b9543993df0b71176d755f720f7",
          "phone_sha256": "7e3308159fc7cca243cef8a01acc25f18cd62d0d1ad92a6d38c3107d9aa3d8cc",
          "marketing_consent": true
        },
        "line_items": [
          {
            "id": "A-1-L1",
            "sku": "SKU-1",
            "title": "Mavi Elbise",
            "quantity": 2,
            "unit_price": "90.00",
            "discount": "0",
            "net_amount": "180.00"
          }
        ]
      }
    ]
  }'
```

The answer is `202 Accepted`:

```json
{
  "accepted": 1,
  "rejected": 0,
  "stale": 0,
  "errors": [],
  "warnings": [],
  "request_id": "6f1c0e5a-2b7d-4c1e-9a43-0d8f2c1b7e55"
}
```

`accepted` is the number of orders that Optifeed stored. A `202` answer can also have rejected and stale orders, so read `rejected`, `stale`, `errors` and `warnings` in each answer. [Errors](/docs/api/errors#errors-and-warnings-of-records) explains each field.

## Order fields

| Field | Type | Required | Rules | When you do not send it |
| --- | --- | --- | --- | --- |
| `id` | Text or whole number | Yes | Your id of the order. 255 characters at most. | Error `required`. |
| `created_at` | Time | Yes | The time of the order. | Error `required`. |
| `updated_at` | Time | Yes | The time of the last change of the order. 24 hours in the future at most. | Error `required`. |
| `cancelled_at` | Time | No | The time of the cancellation. | The order is not cancelled. |
| `currency` | Text | Yes | An ISO 4217 code, for example `TRY`. | Error `required`. |
| `total` | Amount | Yes | The total of the order. | Error `required`. |
| `subtotal` | Amount | No | The subtotal of the order. | No value. |
| `discount` | Amount | No | The discount of the order. | `0` |
| `tax` | Amount | No | The tax of the order. | `0` |
| `shipping` | Amount | No | The shipping cost of the order. | `0` |
| `financial_status` | Text | No | Your payment status, for example `paid` or `refunded`. 1,000 characters at most. | No value. |
| `fulfillment_status` | Text | No | Your delivery status, for example `fulfilled`. 1,000 characters at most. | No value. |
| `test` | Boolean | No | `true` for a test order. | `false` |
| `customer` | Object | Yes | The customer of the order. See [The customer object](#the-customer-object). | Error `required`. |
| `line_items` | List | Yes | 1 or more line items. | Error `required`. |

Optifeed does not store a key that is not in this table.

### Line item fields

| Field | Type | Required | Rules | When you do not send it |
| --- | --- | --- | --- | --- |
| `id` | Text or whole number | No | Your id of the line. 255 characters at most. | No value. |
| `sku` | Text or whole number | Yes | The `sku` of the product, as in [Products](/docs/api/products). 255 characters at most. | Error `required`. |
| `title` | Text | No | The name of the product. 1,000 characters at most. | No value. |
| `quantity` | Whole number | Yes | 1 or more. | Error `required`. |
| `unit_price` | Amount | No | The price of one unit. | No value. |
| `discount` | Amount | No | The discount of the line. | `0` |
| `net_amount` | Amount | No | The net amount of the line. | No value. |

## Formats

### Amounts

Send each amount as decimal text, for example `"199.90"`.

- Put a dot before the decimals. Send 2 decimals at most.
- Send an amount from `0` to `9999999999.99`. A negative amount is an error, so for a refund, send the order again with the lower `total`.
- A JSON number, for example `199.90`, gets the error `amount_not_text`, because a JSON number can change the decimals.
- Other text, for example `"199,90"`, gets the error `invalid_amount`.

### Times

Send each time in ISO 8601 with a time zone offset, for example `"2026-11-20T14:05:00+03:00"`.

- `Z` is the offset of UTC, for example `"2026-11-20T11:05:00Z"`.
- You can send up to 9 decimals of a second.
- A time with no offset, or a date that does not exist, for example `2026-02-30`, gets the error `invalid_date`.
- An `updated_at` more than 24 hours in the future gets the error `future_date`.

Optifeed stores each time in UTC.

### Currency

Send `currency` as an ISO 4217 code of 3 letters, for example `TRY` or `EUR`. Optifeed accepts lowercase and stores uppercase. A code that is not in ISO 4217, for example `BTC`, gets the error `invalid_currency`.

### Statuses

Optifeed stores `financial_status` and `fulfillment_status` as text. The RFM calculation does not read them. To take a cancelled order out of RFM, send `cancelled_at`.

## The customer object

Each order has one customer object. It has the fields of a customer of [Customers](/docs/api/customers#customer-fields), but no `updated_at`. The `updated_at` of the order is the time of its customer.

```json
"customer": {
  "id": "C-9",
  "email_sha256": "9b00b0b820caf9556ca074ae455f87d32be94b9543993df0b71176d755f720f7",
  "phone_sha256": "7e3308159fc7cca243cef8a01acc25f18cd62d0d1ad92a6d38c3107d9aa3d8cc",
  "marketing_consent": true
}
```

- The customer needs a key: a valid contact hash or an `id`. A customer with no key rejects the order with the error `customer_key_missing`.
- A contact hash that is not 64 hexadecimal characters gets the warning `invalid_hash`. Optifeed drops the value and keeps the order.
- A `gender`, `city` or `country` in another format gets the warning `invalid_value`. Optifeed drops the value and keeps the order.
- A `marketing_consent` that is not `true` or `false` rejects the order.
- A customer field that the order does not send keeps its stored value.
- In an error or a warning, the `param` of a customer field starts with `customer.`, for example `customer.email_sha256`.

[Customers](/docs/api/customers#contact-hashes) gives the rule of each contact hash, [the key of a customer](/docs/api/customers#the-key-of-a-customer) and [the marketing consent](/docs/api/customers#marketing-consent).

## Update an order

Send the full order again, with the same `id` and a newer `updated_at`. The new version replaces the stored order and all of its line items. A line item that the new version does not have is removed.

- For a refund, send the lower `total` and your new `financial_status`.
- For a cancellation, send `cancelled_at`.
- Send the current customer object with each version.

An order of this API never replaces an order that Optifeed reads from another source, for example from a store platform, also when the two have the same id.

### The stale rule

Optifeed keeps the newest version of each order. It compares the `updated_at` of each order with the stored order that has the same `id`.

- An order with an older `updated_at` is stale. Optifeed does not store it and counts it in `stale`.
- An order with the same `updated_at` replaces the stored order. So you can send a request again after a timeout.
- When one request has two orders with one `id`, Optifeed stores the order with the newest `updated_at`. It counts the older order as stale. When the two have the same `updated_at`, the later order in the list replaces the earlier one, and both count as accepted.

## After the answer

1. Optifeed stores each accepted order before the answer.
2. A background job processes the stored orders after the answer.
3. Then Optifeed calculates the RFM segments again.

The answer does not tell you when steps 2 and 3 end.

The RFM calculation uses the `created_at` and the `total` of each order. It leaves out:

- an order with `cancelled_at`,
- an order with `test` set to `true`,
- an order that is older than the RFM window of your company. The window is 12 months by default.

## Errors and warnings

These errors refuse the full request, and Optifeed stores nothing:

| Code | Status | When |
| --- | --- | --- |
| `invalid_json` | `400` | The body is not valid JSON. |
| `invalid_batch` | `400` | The body has no `orders` list, or the list is empty. |
| `batch_too_large` | `400` | The list has more than 1,000 orders. |
| `payload_too_large` | `413` | The body is larger than 5 MB. |
| `order_log_busy` | `503` | Optifeed is busy with the orders of your company. Send the same batch again. |

These codes reject one order in a `202` answer:

| Code | Example `param` | When |
| --- | --- | --- |
| `not_an_object` | `null` | The order is not a JSON object. |
| `required` | `total`, `line_items[0].sku` | A required field is missing or `null`. |
| `invalid_type` | `line_items`, `test`, `customer.marketing_consent` | The value has the wrong type, for example an empty `line_items` list or a `quantity` of `0`. |
| `too_long` | `id`, `line_items[0].title` | The value is too long. |
| `invalid_currency` | `currency` | The currency is not an ISO 4217 code. |
| `amount_not_text` | `total` | An amount is a JSON number. |
| `invalid_amount` | `tax` | An amount is not decimal text with 2 decimals at most. |
| `invalid_date` | `created_at` | A time is not ISO 8601 with an offset. |
| `future_date` | `updated_at` | `updated_at` is more than 24 hours in the future. |
| `customer_key_missing` | `customer` | The customer has no valid contact hash and no `id`. |

These codes keep the order:

| Code | Example `param` | When |
| --- | --- | --- |
| `invalid_hash` | `customer.email_sha256` | A contact hash is not 64 hexadecimal characters. Optifeed dropped it. |
| `invalid_value` | `customer.gender` | The `gender`, `city` or `country` is not in a permitted format. Optifeed dropped it. |
| `customer_deleted` | `customer` | You [deleted the customer](/docs/api/customers#delete-a-customer), and the order is not newer than the delete. Optifeed stored the order with no customer. |

[Errors](/docs/api/errors) gives the codes of the access token, the company and the rate limit.
