---
title: Campaigns
description: Send the discounts that your shop gives in the cart with POST /v1/campaigns, and end a campaign with DELETE /v1/campaigns/{id}.
---

A campaign is a discount that your shop gives in the cart, not on the product page. Optifeed writes the cart price of each product from your campaigns, and puts the campaigns that Meta supports into the Meta offers feed.

## The shelf discount and the cart discount

Put the shelf discount in the `sale_price` of the [product](/docs/api/products#prices). Send only a cart discount as a campaign.

A discount in both places gives the cart price the discount two times. For example, a product of 200 TRY has a shelf discount of 20%, so its `sale_price` is 160 TRY. When the same 20% also comes as a campaign, the cart price is 128 TRY, but the shopper pays 160 TRY.

## Send campaigns

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

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

```bash
curl https://api.optifeed.com/v1/campaigns \
  -H "Authorization: Bearer $OPTIFEED_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "campaigns": [
      {
        "id": "BF-2026",
        "name": "Black Friday 20%",
        "discount_type": "percentage",
        "value": "20",
        "currency": "TRY",
        "applies_to": "item",
        "min_quantity": 1,
        "min_subtotal": "0",
        "starts_at": "2026-11-27T00:00:00+03:00",
        "ends_at": "2026-11-30T23:59:59+03:00",
        "priority": 1,
        "active": true,
        "targets": {
          "all_products": false,
          "skus": ["SKU-1"],
          "item_group_ids": [],
          "categories": ["Giyim > Elbise"],
          "brands": []
        },
        "conditions": {
          "coupon": false,
          "member_groups": false,
          "payment": false,
          "once_per_member": false,
          "days": false,
          "hours": false,
          "excludes_discounted": false
        },
        "updated_at": "2026-11-26T10: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 stores each accepted campaign before the answer. The first accepted campaign or product creates the catalog of the API in Optifeed.

## Campaign fields

| Field | Type | Required | Rules | When you do not send it |
| --- | --- | --- | --- | --- |
| `id` | Text or whole number | Yes | Your id of the campaign. 255 characters at most. | Error `required`. |
| `name` | Text | No | 1,000 characters at most. | No value, and the warning `content_gap`. |
| `discount_type` | Text | Yes | `percentage`, `fixed_amount`, `fixed_price` or `other`. | Error `required`. |
| `value` | Amount | Yes, except for `other` | The discount, as decimal text, for example `"20"` or `"50.00"`. A `percentage` is 100 at most. | Error `required`. For `other`: no value. |
| `currency` | Text | No | An ISO 4217 code. The currency of `value` and `min_subtotal`. | No value. |
| `applies_to` | Text | No | `item` or `cart`. | `item` |
| `min_quantity` | Whole number | No | 1 or more. | No value. |
| `paid_quantity` | Whole number | No | 1 or more. "Buy 3, pay 2" is `min_quantity` 3 and `paid_quantity` 2. | No value. |
| `min_subtotal` | Amount | No | The minimum amount for the discount. | No value. |
| `coupon_code` | Text | No | 255 characters at most. A code sets the condition `coupon` to `true`. | No value. |
| `starts_at` | Time | Yes | The start of the campaign. | Error `required`. |
| `ends_at` | Time | No | The end of the campaign. It cannot be before `starts_at`. | No end, and the warning `content_gap`. |
| `priority` | Whole number | No | 0 or more. The smaller number comes first. | The cart price reads it as `0`. |
| `active` | Boolean | No | `false` stops the campaign. | `true` |
| `targets` | Object | No | The products of the campaign. See [Targets](#targets). | The campaign covers no product. |
| `conditions` | Object | No | See [Conditions](#conditions). | Each condition is `false`. |
| `updated_at` | Time | Yes | The time of the last change of the campaign. 24 hours in the future at most. | Error `required`. |

Send each amount as decimal text and each time in ISO 8601 with an offset. [Orders](/docs/api/orders#formats) gives the formats. Optifeed ignores a key that is not in this table.

### Targets

`targets` tells Optifeed which products are in the campaign.

| Key | Value |
| --- | --- |
| `all_products` | `true` puts each product in the campaign. The default is `false`. |
| `skus` | A list of `sku` values. |
| `item_group_ids` | A list of `item_group_id` values. |
| `categories` | A list of `category` values. |
| `brands` | A list of `brand` values. |

- A product is in the campaign when its `sku`, `item_group_id`, `category` or `brand` is in the list of that field.
- A value must be the full text of the field of the product. For example, `"Elbise"` does not match the category `"Giyim > Elbise"`.
- A list has 10,000 values at most. Each value is text or a whole number of 255 characters at most.
- Another key, for example `sku`, gets the error `invalid_key`.
- A campaign with no `targets` covers no product.

### Conditions

`conditions` is an object of `true` or `false` values. A key that you do not send is `false`. Another key gets the error `invalid_key`, so a typo does not change an offer.

| Key | Meaning | Cart price | Meta offer |
| --- | --- | --- | --- |
| `coupon` | The shopper needs a coupon code. | Stops it. | Stops it. |
| `member_groups` | Only some member groups get the discount. | Stops it. | Stops it. |
| `payment` | Only some payment methods get the discount. | Stops it. | Stops it. |
| `once_per_member` | A member gets the discount one time. | No effect. | Stops it. |
| `days` | The discount applies only on some days. | Stops it. | Stops it. |
| `hours` | The discount applies only at some hours. | Stops it. | Stops it. |
| `excludes_discounted` | A product with a shelf discount gets no discount. | Skips such a product. | Meta gets the condition. |

## The stale rule

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

- A campaign with an older `updated_at` does not replace the stored campaign. Optifeed counts it in `stale`.
- A campaign with the same `updated_at` replaces the stored campaign. So you can send a request again after a timeout.
- When one request has two campaigns with one `id`, Optifeed stores the campaign with the newest `updated_at`. With the same `updated_at`, it stores the later one in the list. Both count as accepted.

A campaign that a request does not send stays. Only `DELETE /v1/campaigns/{id}` ends a campaign.

## Where a campaign goes

### The cart price

Each hour, Optifeed writes your products into one file for your catalog. The file gives each product four fields from your campaigns: `cart_campaign_price`, `cart_campaign_name`, `cart_campaign_start_date` and `cart_campaign_end_date`. Your exports can send them to a channel.

A campaign gives a product a cart price when all of these are true at the time of the file:

- The campaign is active, it started and it did not end.
- `discount_type` is `percentage` or `fixed_amount`.
- `min_quantity` is 1, or you did not send it.
- The conditions `coupon`, `member_groups`, `payment`, `days` and `hours` are `false`, and the campaign has no `coupon_code`.
- The product is in the [targets](#targets).
- The base price of the product is more than 0, and not less than `min_subtotal`. The base price is `sale_price`, or `price` when the product has no `sale_price`.
- The campaign has no `currency`, or the same currency as the base price.

A `percentage` gives the base price minus the percentage, with 2 decimals. A `fixed_amount` gives the base price minus `value`. A result of 0 or less gives no cart price. For example, a `sale_price` of 149.90 TRY and a campaign of 20% give a `cart_campaign_price` of `119.92`.

When more than one campaign gives a price, the campaign with the smallest `priority` wins. With the same `priority`, the `id` that comes first in text order wins.

### The Meta offers feed

When your catalog has a Meta offers feed export, Optifeed puts each campaign that Meta supports into that feed. Meta does not support:

- a `fixed_price` or `other` campaign,
- a coupon: a `coupon_code`, or the condition `coupon`,
- the conditions `member_groups`, `payment`, `once_per_member`, `days` or `hours`,
- a `percentage` with decimals, for example `"12.5"`,
- a `min_quantity` of more than 1 together with a `min_subtotal` of more than 0.

The feed also leaves out a campaign that is not active, that ended, or whose targets name no product of the export.

- `coupon_code` never goes to Meta.
- Meta needs the name and the end of an offer. So a campaign with no `name` or no `ends_at` gets the warning `content_gap`.
- Send `currency` with a `fixed_amount` campaign. With no `currency`, Meta gets the amount in TRY.

## End a campaign

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

```bash
curl -X DELETE https://api.optifeed.com/v1/campaigns/BF-2026 \
  -H "Authorization: Bearer $OPTIFEED_TOKEN"
```

The answer is `202 Accepted`:

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

- Encode the `id` in the path. An `id` can have a dot.
- The next Meta offers feed and the next product file do not have the campaign.
- An `id` that Optifeed does not have gets `404` with the code `not_found` and `param` `id`. A campaign that you ended before also gets `404`.
- A later campaign with the same `id` and a newer or the same `updated_at` is stored again. A campaign with an older `updated_at` is stale, and the campaign stays ended.

## 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 `campaigns` list, or the list is empty. |
| `batch_too_large` | `400` | The list has more than 1,000 campaigns. |
| `payload_too_large` | `413` | The body is larger than 5 MB. |
| `catalog_inactive` | `409` | The catalog of the API is not active. Contact Optifeed support. |
| `not_found` | `404` | Only for `DELETE`: Optifeed has no campaign with the `id`. |

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

| Code | Example `param` | When |
| --- | --- | --- |
| `not_an_object` | `null` | The campaign is not a JSON object. |
| `required` | `id`, `value`, `starts_at` | A required field is missing or `null`. |
| `invalid_type` | `targets.skus`, `conditions.payment`, `priority` | The value has the wrong type. |
| `too_long` | `name`, `coupon_code`, `targets.skus` | The value or the list is too long. |
| `invalid_value` | `discount_type`, `value`, `ends_at` | The value is not permitted, a percentage is more than 100, or `ends_at` is before `starts_at`. |
| `invalid_currency` | `currency` | The currency is not an ISO 4217 code. |
| `amount_not_text` | `value` | An amount is a JSON number. |
| `invalid_amount` | `min_subtotal` | An amount is not decimal text with 2 decimals at most. |
| `invalid_date` | `starts_at` | A time is not ISO 8601 with an offset. |
| `future_date` | `updated_at` | `updated_at` is more than 24 hours in the future. |
| `invalid_key` | `targets.sku`, `conditions.excludes_discount` | The key is not a key of `targets` or `conditions`. |

This code keeps the campaign:

| Code | `param` | When |
| --- | --- | --- |
| `content_gap` | `name`, `ends_at` | Meta needs this field. Optifeed accepted the campaign without it. |

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