---
title: Customers
description: Send customers that have no order yet, or changes to a customer, with POST /v1/customers.
---

Each order already brings its customer. Use this endpoint for a customer with no order yet, or for a change to a customer, for example a new phone number or a new marketing consent.

## Send customers

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

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

```bash
curl https://api.optifeed.com/v1/customers \
  -H "Authorization: Bearer $OPTIFEED_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customers": [
      {
        "id": "C-9",
        "email_sha256": "1d49b8835542270cfed33d61e2285c702fe6a5cdb7b56c7b782e07825434f05f",
        "email_normalized_sha256": "213e9e6323fb2e755d9a56f18522623dfba1710a3aff5355d1b8cb4dc3bb853c",
        "phone_sha256": "7e3308159fc7cca243cef8a01acc25f18cd62d0d1ad92a6d38c3107d9aa3d8cc",
        "phone_e164_sha256": "57c4176feab36c8b2d9536954c377aee3fa760184cbdb9c3a431fbc707817386",
        "marketing_consent": true,
        "gender": "female",
        "city": "İzmir",
        "country": "TR",
        "updated_at": "2026-11-28T10:00:00+03:00"
      }
    ]
  }'
```

The answer is `202 Accepted`:

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

Optifeed writes the accepted customers before the answer. The next audience sync sends their new hashes. [Errors](/docs/api/errors#errors-and-warnings-of-records) explains each field of the answer.

## Customer fields

| Field | Type | Required | Rules | When you do not send it |
| --- | --- | --- | --- | --- |
| `id` | Text or whole number | No | Your id of the customer. 255 characters at most. | Optifeed removes the stored value. |
| `email_sha256` | Hash | No | See [Contact hashes](#contact-hashes). | Optifeed removes the stored value. |
| `email_normalized_sha256` | Hash | No | See [Contact hashes](#contact-hashes). | Meta and Google use `email_sha256`. |
| `phone_sha256` | Hash | No | See [Contact hashes](#contact-hashes). | Optifeed removes the stored value. |
| `phone_e164_sha256` | Hash | No | See [Contact hashes](#contact-hashes). | Optifeed removes the stored value. |
| `marketing_consent` | Boolean | No | `true` or `false`. See [Marketing consent](#marketing-consent). | The stored consent stays. |
| `gender` | Text | No | `female` or `male`. | Optifeed removes the stored value. |
| `city` | Text | No | 1 to 100 characters. Optifeed removes the spaces at the start and the end. | Optifeed removes the stored value. |
| `country` | Text | No | An ISO 3166-1 alpha-2 code, for example `TR`. Optifeed accepts lowercase and stores uppercase. | Optifeed removes the stored value. |
| `updated_at` | Time | Yes | The time of the last change of the customer, in ISO 8601 with an offset. 24 hours in the future at most. | Error `required`. |

A customer needs a key: a valid contact hash or an `id`. A customer with no key gets the error `customer_key_missing`.

A value in another format does not always reject the customer:

- A contact hash that is not 64 hexadecimal characters gets the warning `invalid_hash`.
- A `gender`, `city` or `country` in another format gets the warning `invalid_value`.

In these cases Optifeed drops the value and keeps the customer. A `marketing_consent` that is not `true` or `false` rejects the customer, because a dropped `false` would put the customer into the audiences.

Optifeed does not store a key that is not in this table. The customer object of an order has the same fields, except `updated_at`. [Orders](/docs/api/orders#the-customer-object) gives the differences.

## Contact hashes

Optifeed never gets the email or the phone number of a customer. Your system sends SHA-256 hashes of them.

The ad platforms match customers with different rules. So a customer has four hash fields, one for each rule. Send each hash that you can make.

| Field | The value before the hash | Channels |
| --- | --- | --- |
| `email_sha256` | The email in lowercase, with no spaces at the start or the end. | OpenAI, TikTok |
| `email_normalized_sha256` | The same. For `gmail.com` and `googlemail.com`, also remove the dots and the `+tag` from the part before `@`. | Meta, Google |
| `phone_sha256` | Digits only, with the country code, with no plus sign and no leading zero, for example `905321234567`. | Meta, Google |
| `phone_e164_sha256` | E.164 with the plus sign, for example `+905321234567`. | OpenAI, TikTok |

- Send each hash as 64 hexadecimal characters. Optifeed accepts uppercase and stores lowercase.
- When a customer has no `email_normalized_sha256`, Meta and Google use `email_sha256`. For most addresses the two hashes are the same. A Gmail address with dots or a `+tag` then matches less often.

For example, the email `Ayse.Kaya+promo@gmail.com` gives these two values before the hash:

```bash
printf '%s' 'ayse.kaya+promo@gmail.com' | shasum -a 256   # email_sha256
printf '%s' 'aysekaya@gmail.com' | shasum -a 256          # email_normalized_sha256
```

## The key of a customer

Optifeed finds the stored customer by a key. The key is the first valid field in this order:

1. `email_sha256`
2. `email_normalized_sha256`
3. `phone_sha256`
4. `phone_e164_sha256`
5. `id`

So the `id` is the key only when the customer has no valid hash. Optifeed stores the `id` with the customer in each case.

A customer with another key is another customer. For example, a customer first comes with only `phone_sha256`. Later the same person comes with `email_sha256` and `phone_sha256`. The key is now the email hash, so Optifeed stores a second customer. Send the same hashes for a customer each time.

Two orders with no `id` and a later order with an `id` give one customer when they have the same email hash. The customer keeps the `id`.

## Change a customer

A customer replaces the full stored customer with the same key. A field that the new customer does not send is removed, for example the `city`. The orders of the customer stay with the customer.

There is one exception: a customer with no `marketing_consent` keeps the stored consent.

An order also changes its customer, with one difference: a customer field that the order does not send keeps its stored value.

## Marketing consent

`marketing_consent` tells Optifeed if the customer agreed to marketing.

| Value | Effect |
| --- | --- |
| `true` | The customer can go to the audiences of the ad platforms. |
| `false` | The customer stays in RFM and has an RFM segment, but goes to no audience. |
| Not sent | The stored consent stays. A customer that never got a consent value can go to the audiences. |

- The newest consent wins. A consent with an older `updated_at` does not replace a newer one. So an upload of old orders does not undo a newer `false`.
- When two records have the same `updated_at`, the record that arrives later wins.
- When one request has more than one version of a customer, Optifeed stores the newest version, with the newest consent of the request.

[Data and privacy](/docs/api/data-and-privacy#marketing-consent-and-the-audiences) explains which customers go to the audiences.

## A customer with no order

Optifeed stores a customer with no order, but the customer has no RFM score. So no audience gets the customer before the first order.

## The stale rule

Optifeed keeps the newest version of each customer. It compares the `updated_at` of the customer with the newest stored customer or order of the same key.

- A customer with an older `updated_at` is stale. Optifeed does not store it and counts it in `stale`.
- A customer with the same `updated_at` replaces the stored customer.
- When one request has two customers with one key, Optifeed stores the newest. It counts the older one as stale. When the two have the same `updated_at`, the later one in the list replaces the earlier one, and both count as accepted.

## Delete a customer

Use this endpoint when a person asks you to erase their data, for example under KVKK or GDPR.

`DELETE https://api.optifeed.com/v1/customers/{id}`

```bash
curl -X DELETE https://api.optifeed.com/v1/customers/C-1001 \
  -H "Authorization: Bearer $OPTIFEED_TOKEN"
```

The answer is `202 Accepted`:

```json
{
  "id": "C-1001",
  "deleted": true,
  "request_id": "6f1c0e5a-2b7d-4c1e-9a43-0d8f2c1b7e55"
}
```

- The `id` is the `id` that you sent for the customer. Encode it in the path.
- Optifeed deletes each customer of your company with that `id`. A member who changed the email address can be two customers in Optifeed, and the delete removes both.
- Optifeed deletes the contact hashes, the marketing consent, the `gender`, the `city` and the `country` of the customer.
- The orders stay, with no customer. Optifeed removes the link from each order to the customer, and the `customer` object from the stored copy of each order.
- The RFM scores and the segments change at the next calculation, a few minutes later. So the answer is `202`, not `200`.
- An `id` that Optifeed does not have gets `404` with the code `not_found` and `param` `id`. A second delete of the same `id` also gets `404`.
- A customer or an order with an `updated_at` at or before the time of the delete does not bring the customer back. Optifeed counts such a customer as stale. It stores such an order with no customer and gives the warning `customer_deleted`.
- A record with a newer `updated_at` creates the customer again, for example a new order of the same person.
- Add `?dry_run=true` to check the `id`. The answer is the `202` or the `404` of a real delete, and Optifeed deletes nothing.
- When Optifeed is busy with the orders of your company, the answer is `503` with the code `order_log_busy`. Send the delete again.

## 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 `customers` list, or the list is empty. |
| `batch_too_large` | `400` | The list has more than 1,000 customers. |
| `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 customer in a `202` answer. The `param` has no `customer.` prefix here.

| Code | Example `param` | When |
| --- | --- | --- |
| `not_an_object` | `null` | The customer is not a JSON object. |
| `required` | `updated_at` | `updated_at` is missing or `null`. |
| `invalid_type` | `id`, `marketing_consent` | The value has the wrong type. |
| `too_long` | `id` | The `id` is longer than 255 characters. |
| `invalid_date` | `updated_at` | `updated_at` is not ISO 8601 with an offset. |
| `future_date` | `updated_at` | `updated_at` is more than 24 hours in the future. |
| `customer_key_missing` | `null` | The customer has no valid contact hash and no `id`. |

These codes keep the customer:

| Code | Example `param` | When |
| --- | --- | --- |
| `invalid_hash` | `email_sha256` | A contact hash is not 64 hexadecimal characters. Optifeed dropped it. |
| `invalid_value` | `gender`, `city`, `country` | The value is not in a permitted format. Optifeed dropped it. |

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