Skip to content

pos-apply-coupon ​

Method: POST
Path: /pos/carts/{id}/coupon

Tags: Coupons & promotions

Summary ​

Apply coupon

Description ​

Applies a coupon code to the cart. Returns a fully updated Cart object with recalculated totals.

Pos SDK Usage ​

SDK Method: pos.applyCoupon()

Example:

typescript
const { data, error } = await pos.applyCoupon(
  { id: "01H9CART12345ABCDE" },
  { coupon_code: "FLAT100OFF" }
);

if (error) {
  console.error("Failed to apply coupon:", error.message);
} else {
  console.log("Coupon applied, new total:", data.cart.grand_total);
  console.log("Discount amount:", data.cart.coupon_discount_amount);
}

TypeScript Definition ​

typescript
"pos-apply-coupon": {
        parameters: {
            query?: never;
            header?: never;
            path: {
                /** @description Cart ID */
                id: string;
            };
            cookie?: never;
        };
        requestBody: {
            content: {
                "application/json": {
                    /** @example FLAT100OFF */
                    coupon_code: string;
                };
            };
        };
        responses: {
            /** @description OK */
            200: {
                headers: {
                    [name: string]: unknown;
                };
                content: {
                    "application/json": {
                        message: string;
                        success: boolean;
                        content: {
                            cart: components["schemas"]["CartRead"];
                        };
                        /** @description Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event. */
                        events: components["schemas"]["StorefrontResponseEvent"][];
                    };
                };
            };
            400: components["responses"]["BadRequest"];
            401: components["responses"]["Unauthorized"];
            403: components["responses"]["Forbidden"];
            /** @description The active cart was not found. */
            404: components["responses"]["NotFound"];
            408: components["responses"]["RequestTimeout"];
            500: components["responses"]["InternalServerError"];
            504: components["responses"]["GatewayTimeout"];
        };
    };

Component References ​

ReferenceResolves To
components["schemas"]["CartRead"]CartRead
components["schemas"]["StorefrontResponseEvent"]StorefrontResponseEvent
components["responses"]["BadRequest"]BadRequest
components["responses"]["Unauthorized"]Unauthorized
components["responses"]["Forbidden"]Forbidden
components["responses"]["NotFound"]NotFound
components["responses"]["RequestTimeout"]RequestTimeout
components["responses"]["InternalServerError"]InternalServerError
components["responses"]["GatewayTimeout"]GatewayTimeout

Parameters ​

  • id (path): Cart ID

Request Body ​

Content Types: application/json

Responses ​

200 ​

OK

400 ​

Bad request

401 ​

Authentication failed. Codes include token-required, token-expired and token_not_valid for an invalid or expired token.

403 ​

Access denied. token-required requires an authenticated session; permission-denied means the caller cannot access this resource. On POS, session-expired requires signing in again.

404 ​

Requested resource not found

408 ​

500 ​

The request failed because of an unexpected error.

504 ​

The request timed out.

OpenAPI Definition ​

json
{
  "operationId": "pos-apply-coupon",
  "summary": "Apply coupon",
  "description": "Applies a coupon code to the cart. Returns a fully updated `Cart` object with recalculated totals.",
  "parameters": [
    {
      "name": "id",
      "in": "path",
      "description": "Cart ID",
      "required": true,
      "schema": {
        "type": "string",
        "maxLength": 128,
        "minLength": 1,
        "pattern": "^[A-Za-z0-9_-]{1,128}$"
      }
    }
  ],
  "requestBody": {
    "description": "",
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "coupon_code": {
              "type": "string",
              "examples": [
                "FLAT100OFF"
              ],
              "minLength": 1,
              "pattern": "\\S"
            }
          },
          "required": [
            "coupon_code"
          ]
        }
      }
    }
  },
  "responses": {
    "200": {
      "description": "OK",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "success": {
                "type": "boolean"
              },
              "content": {
                "properties": {
                  "cart": {
                    "$ref": "#/components/schemas/CartRead"
                  }
                },
                "required": [
                  "cart"
                ],
                "type": "object"
              },
              "events": {
                "description": "Analytics events to emit for the change this request made, each with a server-issued `event_id`. Replay them to your analytics destinations so your client-side and server-side copies of the same action dedupe. Empty when the request produced no analytics event.",
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/StorefrontResponseEvent"
                }
              }
            },
            "required": [
              "message",
              "success",
              "content",
              "events"
            ]
          }
        }
      },
      "links": {
        "CreateOrderFromCart": {
          "operationId": "create-pos-order",
          "requestBody": {
            "cart_id": "$request.path.id"
          },
          "description": "Create a POS order from a cart."
        }
      }
    },
    "400": {
      "$ref": "#/components/responses/BadRequest"
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    },
    "403": {
      "$ref": "#/components/responses/Forbidden"
    },
    "404": {
      "description": "The active cart was not found.",
      "$ref": "#/components/responses/NotFound"
    },
    "408": {
      "$ref": "#/components/responses/RequestTimeout"
    },
    "500": {
      "$ref": "#/components/responses/InternalServerError"
    },
    "504": {
      "$ref": "#/components/responses/GatewayTimeout"
    }
  },
  "externalDocs": {
    "url": "https://llm-docs.commercengine.io/admin-pos/operations/pos-apply-coupon"
  },
  "security": [
    {
      "Authorization": []
    }
  ],
  "tags": [
    "Coupons & promotions"
  ],
  "x-speakeasy-group": "pos",
  "x-speakeasy-name-override": "applyCoupon"
}

Auto-generated from OpenAPI spec and TypeScript definitions

Last updated: