> This page is for Entria API Reference.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.navipartner.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.navipartner.com/_mcp/server.

# Replace the discount codes applied to a cart

POST https://api.entria.app/api/cart/discounts
Content-Type: application/json

Sets the complete set of discount codes on the cart — send every code the shopper should have, `[]` to clear — and returns the updated cart with a verdict per code. Partial success is normal: an unknown code never discards the valid ones sent with it. A real code the cart does not qualify for yet is kept as `pending` and applies on its own once it does. Automatic promotions are not codes; they appear in `cart.discounts` with `source: AUTOMATIC`, cannot be added or removed here, and are ignored if their code is sent. Safe to retry: the request states the desired end state. Does not extend the reservation.

Reference: https://docs.navipartner.com/entria-api/entria-api-reference/cart/post-update-cart-discounts

## Request

### Headers

- `x-entria` (string, required) — Identifies which store this request is for. Required on every store-scoped route. It is not authentication and not a secret — it grants no privileges and is safe to send from a browser. You receive the value once your Entria backend has been created and configured. Missing header returns 400; an unknown store returns 404.

### Body (application/json)

This endpoint expects an object.

- `cartId` (string, required) — Id of the cart.
- `codes` (list of string, required) — Complete desired set of discount codes. Replaces whatever is on the cart; `[]` clears it.

## Response

### 200

The updated cart and a verdict for every code in the request.

- `cart` (Cart, required)
- `accepted` (list of string, required) — Shopper-entered codes on the cart after this write that produce a discount (`cart.discounts` with `source: CODE`). Automatic promotions are not codes and are never listed here, even if their code was sent.
- `pending` (list of string, required) — Real codes on the cart after this write that do not qualify yet. The same list as `cart.pendingDiscountCodes`; they apply on their own once the cart qualifies.
- `rejected` (list of CartDiscountRejection, required) — Codes from this request that cannot apply in this session. Not kept anywhere.

## Errors

### 400 Bad Request Error

The request body failed validation (more than 10 codes, empty code).

- `error` (string, required)
- `code` (string, optional)
- `details` (list of ErrorResponseDetailsItems, optional) — Per-field validation failures; present when code is VALIDATION_ERROR.
- `success` (boolean, optional, deprecated) — Deprecated. Use code === VALIDATION_ERROR.
- `errors` (list of any, optional, deprecated) — Deprecated. Raw zod issues; use details instead.

### 401 Unauthorized Error

The cart belongs to a logged-in member (`metadata.member_key`) and the request does not carry that member’s token — none, or another member’s (`code: MEMBER_TOKEN_REQUIRED`); or the member Bearer is ours but expired, not yet valid or minted for another store (`code: MEMBER_TOKEN_INVALID`). Either way, log the member in again and retry with their token.

- `error` (string, required)
- `code` (string, optional)
- `details` (list of ErrorResponseDetailsItems, optional) — Per-field validation failures; present when code is VALIDATION_ERROR.
- `success` (boolean, optional, deprecated) — Deprecated. Use code === VALIDATION_ERROR.
- `errors` (list of any, optional, deprecated) — Deprecated. Raw zod issues; use details instead.

### 404 Not Found Error

No cart exists for the given cartId.

- `error` (string, required)
- `code` (string, optional)
- `details` (list of ErrorResponseDetailsItems, optional) — Per-field validation failures; present when code is VALIDATION_ERROR.
- `success` (boolean, optional, deprecated) — Deprecated. Use code === VALIDATION_ERROR.
- `errors` (list of any, optional, deprecated) — Deprecated. Raw zod issues; use details instead.

### 409 Conflict Error

Another write holds the cart (Medusa lock timeout). Safe to retry after `Retry-After` seconds — the request states the desired end state, so a retry cannot double-apply. `code: CART_LOCKED`.

- `error` (string, required)
- `code` (string, optional)
- `details` (list of ErrorResponseDetailsItems, optional) — Per-field validation failures; present when code is VALIDATION_ERROR.
- `success` (boolean, optional, deprecated) — Deprecated. Use code === VALIDATION_ERROR.
- `errors` (list of any, optional, deprecated) — Deprecated. Raw zod issues; use details instead.

### 500 Internal Server Error

An upstream call failed. Re-read the cart before retrying.

- `error` (string, required)
- `code` (string, optional)
- `details` (list of ErrorResponseDetailsItems, optional) — Per-field validation failures; present when code is VALIDATION_ERROR.
- `success` (boolean, optional, deprecated) — Deprecated. Use code === VALIDATION_ERROR.
- `errors` (list of any, optional, deprecated) — Deprecated. Raw zod issues; use details instead.

### 501 Not Implemented Error

This store's backend does not support discount codes yet. `code: DISCOUNTS_NOT_SUPPORTED`.

- `error` (string, required)
- `code` (string, optional)
- `details` (list of ErrorResponseDetailsItems, optional) — Per-field validation failures; present when code is VALIDATION_ERROR.
- `success` (boolean, optional, deprecated) — Deprecated. Use code === VALIDATION_ERROR.
- `errors` (list of any, optional, deprecated) — Deprecated. Raw zod issues; use details instead.

## Types

### Cart

- `id` (string, required)
- `checkoutUrl` (string, required)
- `currencyCode` (string, required)
- `locale` (string, required)
- `email` (string, required, nullable)
- `createdAt` (string, required)
- `updatedAt` (string, required)
- `total` (double, required)
- `subtotal` (double, required)
- `taxTotal` (double, required)
- `customerId` (string, required, nullable)
- `shippingAddressCountry` (string, required, nullable)
- `metadata` (CartMetadata, required)
- `countries` (list of CartCountry, required)
- `items` (list of CartItem, required)
- `reservationToken` (string, optional)
- `reservationExpiration` (string, optional)
- `discountTotal` (double, optional)
- `discountSubtotal` (double, optional)
- `discountTaxTotal` (double, optional)
- `discounts` (list of CartDiscount, optional)
- `pendingDiscountCodes` (list of string, optional)

### CartDiscountRejection

- `code` (string, required)
- `reason` (CartDiscountRejectionReason, required)

### ErrorResponseDetailsItems

- `path` (string, required)
- `message` (string, required)

### CartMetadata

- `reservation_token` (string, optional)
- `reservation_expiration` (string, optional)
- `opportunity_number` (string, optional)
- `checkout_url` (string, optional)
- `member_key` (string, optional) — Present once a member token has bound the cart (on create, `PATCH /api/cart`, `/api/cart/identity` or `/api/cart/lines`): from then on every call on it needs that member’s token. A keyed hash, not personal data, but the same for one member on every cart.

### CartCountry

- `iso2` (string, required)
- `displayName` (string, required)

### CartItem

- `id` (string, required)
- `productType` (string, required)
- `thumbnail` (string, required, nullable)
- `description` (string, required, nullable)
- `metadata` (CartItemMetadata, required)
- `createdAt` (string, required)
- `updatedAt` (string, required)
- `title` (string, required)
- `quantity` (double, required)
- `price` (double, required)
- `basePrice` (double, required)
- `requiresShipping` (boolean, required)
- `taxLines` (list of CartItemTaxLine, required)
- `discountAllocations` (list of CartDiscountAllocation, optional)

### CartDiscount

- `promotionId` (string, required)
- `amount` (double, required)
- `code` (string, optional)
- `source` (enum, optional)
  - Allowed values: `CODE`, `AUTOMATIC`
- `removable` (boolean, optional)

### CartDiscountRejectionReason

- `code` (enum, required)
  - Allowed values: `INVALID`, `USAGE_LIMIT_REACHED`, `BUDGET_EXCEEDED`

### CartItemMetadata

- `date` (string, optional)
- `endTime` (string, optional)
- `startTime` (string, optional)
- `price` (double, optional)
- `isCustomPrice` (boolean, optional)
- `admissionCode` (string, optional)
- `scheduleNumber` (double, optional)
- `scheduleSelection` (enum, optional)
  - Allowed values: `userSelectedSchedule`, `nextAvailableSchedule`
- `productId` (string, optional)
- `externalId` (string, optional)
- `basePrice` (double, optional)
- `activationDate` (string, optional)
- `expirationDate` (string, optional)
- `birthdate` (string, optional)
- `subscription` (boolean, optional)
- `discounts` (list of string, optional)
- `reservationLineId` (string, optional)
- `voucherAmount` (double, optional)
- `membershipLegalText` (string, optional)
- `members` (CartItemMetadataMembers, optional)
- `member` (CartItemMetadataMember, optional)
- `children` (list of CartItemChildMetadata, optional)
- `parentProductId` (string, optional)

### CartItemTaxLine

- `code` (string, required)
- `rate` (double, required)

### CartDiscountAllocation

- `promotionId` (string, required)
- `amount` (double, required)
- `code` (string, optional)

### CartItemMetadataMembers

- `member_first_name` (string, required)
- `member_email` (string, required)

### CartItemMetadataMember

- `firstName` (string, optional)
- `lastName` (string, optional)
- `email` (string, optional)
- `phoneNo` (string, optional)
- `address` (string, optional)
- `city` (string, optional)
- `postCode` (string, optional)
- `country` (string, optional)
- `birthday` (string, optional)

### CartItemChildMetadata

- `productId` (string, optional)
- `externalId` (string, optional)
- `quantity` (double, optional)
- `date` (string, optional)
- `startTime` (string, optional)
- `endTime` (string, optional)
- `scheduleNumber` (double, optional)
- `scheduleSelection` (enum, optional)
  - Allowed values: `userSelectedSchedule`, `nextAvailableSchedule`
- `admissionCode` (string, optional)
- `price` (double, optional)
- `basePrice` (double, optional)
- `discounts` (list of string, optional)
- `voucherAmount` (double, optional)
- `taxRate` (double, optional)
- `total` (double, optional)
- `title` (string, optional)
- `reservationLineId` (string, optional)

## Examples

**Request**

```json
{
  "cartId": "string",
  "codes": [
    "string"
  ]
}
```

**Response**

```json
{
  "cart": {
    "id": "string",
    "checkoutUrl": "string",
    "currencyCode": "string",
    "locale": "string",
    "email": "string",
    "createdAt": "string",
    "updatedAt": "string",
    "total": 1.1,
    "subtotal": 1.1,
    "taxTotal": 1.1,
    "customerId": "string",
    "shippingAddressCountry": "string",
    "metadata": {
      "reservation_token": "string",
      "reservation_expiration": "string",
      "opportunity_number": "string",
      "checkout_url": "string",
      "member_key": "string"
    },
    "countries": [
      {
        "iso2": "string",
        "displayName": "string"
      }
    ],
    "items": [
      {
        "id": "string",
        "productType": "string",
        "thumbnail": "string",
        "description": "string",
        "metadata": {
          "date": "string",
          "endTime": "string",
          "startTime": "string",
          "price": 1.1,
          "isCustomPrice": true,
          "admissionCode": "string",
          "scheduleNumber": 1.1,
          "scheduleSelection": "userSelectedSchedule",
          "productId": "string",
          "externalId": "string",
          "basePrice": 1.1,
          "activationDate": "string",
          "expirationDate": "string",
          "birthdate": "string",
          "subscription": true,
          "discounts": [
            "string"
          ],
          "reservationLineId": "string",
          "voucherAmount": 1.1,
          "membershipLegalText": "string",
          "members": {
            "member_first_name": "string",
            "member_email": "string"
          },
          "member": {
            "firstName": "string",
            "lastName": "string",
            "email": "string",
            "phoneNo": "string",
            "address": "string",
            "city": "string",
            "postCode": "string",
            "country": "string",
            "birthday": "string"
          },
          "children": [
            {
              "productId": "string",
              "externalId": "string",
              "quantity": 1.1,
              "date": "string",
              "startTime": "string",
              "endTime": "string",
              "scheduleNumber": 1.1,
              "scheduleSelection": "userSelectedSchedule",
              "admissionCode": "string",
              "price": 1.1,
              "basePrice": 1.1,
              "discounts": [
                "string"
              ],
              "voucherAmount": 1.1,
              "taxRate": 1.1,
              "total": 1.1,
              "title": "string",
              "reservationLineId": "string"
            }
          ],
          "parentProductId": "string"
        },
        "createdAt": "string",
        "updatedAt": "string",
        "title": "string",
        "quantity": 1.1,
        "price": 1.1,
        "basePrice": 1.1,
        "requiresShipping": true,
        "taxLines": [
          {
            "code": "string",
            "rate": 1.1
          }
        ],
        "discountAllocations": [
          {
            "promotionId": "string",
            "amount": 1.1,
            "code": "string"
          }
        ]
      }
    ],
    "reservationToken": "string",
    "reservationExpiration": "string",
    "discountTotal": 1.1,
    "discountSubtotal": 1.1,
    "discountTaxTotal": 1.1,
    "discounts": [
      {
        "promotionId": "string",
        "amount": 1.1,
        "code": "string",
        "source": "CODE",
        "removable": true
      }
    ],
    "pendingDiscountCodes": [
      "string"
    ]
  },
  "accepted": [
    "string"
  ],
  "pending": [
    "string"
  ],
  "rejected": [
    {
      "code": "string",
      "reason": {
        "code": "INVALID"
      }
    }
  ]
}
```

**SDK Code**

```python
import requests

url = "https://api.entria.app/api/cart/discounts"

payload = {
    "cartId": "string",
    "codes": ["string"]
}
headers = {
    "x-entria": "x-entria",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.entria.app/api/cart/discounts';
const options = {
  method: 'POST',
  headers: {'x-entria': 'x-entria', 'Content-Type': 'application/json'},
  body: '{"cartId":"string","codes":["string"]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.entria.app/api/cart/discounts"

	payload := strings.NewReader("{\n  \"cartId\": \"string\",\n  \"codes\": [\n    \"string\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("x-entria", "x-entria")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.entria.app/api/cart/discounts")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-entria"] = 'x-entria'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"cartId\": \"string\",\n  \"codes\": [\n    \"string\"\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.entria.app/api/cart/discounts")
  .header("x-entria", "x-entria")
  .header("Content-Type", "application/json")
  .body("{\n  \"cartId\": \"string\",\n  \"codes\": [\n    \"string\"\n  ]\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.entria.app/api/cart/discounts', [
  'body' => '{
  "cartId": "string",
  "codes": [
    "string"
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'x-entria' => 'x-entria',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.entria.app/api/cart/discounts");
var request = new RestRequest(Method.POST);
request.AddHeader("x-entria", "x-entria");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"cartId\": \"string\",\n  \"codes\": [\n    \"string\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "x-entria": "x-entria",
  "Content-Type": "application/json"
]
let parameters = [
  "cartId": "string",
  "codes": ["string"]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.entria.app/api/cart/discounts")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```