Implementing the Promotion Engine

The Promotion Engine is a standalone system designed to manage and apply marketing promotions across your e-commerce experience. It allows businesses to define a wide range of promotional rules, such as discounts, product bundles, promo codes, or free gifts, and automatically determine which promotions apply to a given cart.

It works independently of the Loyalty Engine, and focuses solely on evaluating the contents of a shopping cart, matching them against configured promotion rules, and returning the applicable discounts and benefits.

You can use the Promotion Engine to:

  • Automate discount and benefit calculations based on flexible rules
  • Support complex promotion types (e.g., "Buy 2 get 1 free", product bundles, time-limited pricing)
  • Apply multiple promotions with control over stacking, limits, and selection strategies
  • Integrate seamlessly into your e-commerce flow via API

Promotions themselves are created and configured using the Promotion Engine UI, while the Promotion Engine API focuses on the runtime evaluation and application of those promotions.

Unlike the Loyalty Engine, the Promotion Engine does not handle customer identities, profile management, or event tracking. It does not store customer history or trigger promotions based on past actions. Instead, it evaluates each request solely based on the cart contents and the provided purchase context (e.g., location, cart content, promotion scheduling).

This guide walks you through implementing the full API flow, from authentication to cart submission and interpreting the results, so you can successfully integrate promotions into your e-commerce journey.

Authentication

The authentication endpoint is the secure entry point for accessing the Promotion Engine API. It issues a temporary access token in exchange for a valid API key generated through the Authentication Manager. This token must be included in the Authorization header of all subsequent requests to protected endpoints, such as retrieving promotions or submitting a cart for evaluation.

How it works:

  • You provide the client_id and client_secret authentication endpoint.

    The authentication request must include the following body properties:

    • grant_type: must be set to client_credentials
    • scope: must be set to promotions.all
  • The endpoint returns a JWT access token that is valid based on the configuration in the Authentication Manager.
    Store your token securely. Avoid exposing it in client-side code, logs, or public repositories.

  • Use this token as a Bearer token in the Authorization header for all Promotion API calls.

  • When the token expires or becomes invalid, the API will respond with a 401 Unauthorized status code, signaling that you must generate a new token through the authentication endpoint.

Example request

POST /api/v1/auth/token HTTP/1.1
Host: api.<environment>.antavo.com
Authorization: Basic <base64-encoded-client-id-and-client-secret>

{ 
	"grant_type": "client_credentials",
	"scope": "promotions.all" 
}

Replace environment with the name of the environment you currently use.

A successful response returns a token that can be used to authenticate subsequent API requests.

Example response

{
  "access_token": "example_token",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "promotions.all"
}

⚠️ Always treat your client_id, client_secret and access_token as sensitive credentials. Do not expose them in client-side code or logs.

Retrieving Promotions

The Promotion Engine provides endpoints to access promotion configurations. These endpoints are useful for tasks such as:

  • Displaying active promotions to end users
  • Utilizing configuration metadata for validation and auditing
  • Synchronizing promotion data across multiple systems

The responses provided by the Promotion Engine API include comprehensive details about promotions, such as its type, eligibility restrictions, discount configurations, and stacking rules configured in the Promotion Engine UI. This enables you to fully understand how each promotion operates.

Endpoints

  • GET /api/v1/promotions: Fetch the entire catalog of promotions with detailed configuration.
    No request body or query parameters are required for the full list endpoint.

Example request

GET /api/v1/promotions HTTP/1.1
Host: promotion.{environment}.antavo.com
Authorization: Bearer YOUR_ACCESS_TOKEN

Replace environment with the name of the environment you currently use, and YOUR_ACCESS_TOKEN with the token provided by the authentication endpoint.

Example response

{
  "status": "success",
  "metadata": [],
  "payload": [
    {
      "id": "01JW4K7MJJKJB1C58F1CP3K2ZQ",
      "workspaceId": "500",
      "name": "Buy 4 pens total for €10.",
      "status": "active",
      "description": "Buy any 4 pens for a total price of €10.",
      "type": "buyXForTotalAmount",
      "imageURL": "https://antavo.com",
      "priority": 1,
      "currency": "EUR",
      "stackingConfiguration": {
        "selfStackingConfiguration": {
          "isAllowed": true,
          "limit": 5
        },
        "stackingType": "stackable",
        "excludedPromotionIds": null
      },
      "applicationsResetSchedule": null,
      "restriction": {
        "timeRestriction": {
          "start": "2025-08-01 22:45",
          "end": "2025-09-30 22:45",
          "recurringSchedule": null
        },
        "applicationsCountLimit": 0,
        "minTotalBeforeTax": "10",
        "maxTotalBeforeTax": "",
        "storeRestriction": {
          "stores": [],
          "storeGroups": [
            "Germany"
          ]
        },
        "buyXForTotalAmount": {
          "quantity": 4,
          "item": "Stationery",
          "itemType": "category"
        }
      },
      "discount": {
        "buyXForTotalAmount": {
          "groupPriceBeforeTax": "10.00",
          "itemSelectionStrategy": "cheapest"
        }
      }
    },
    {
      "id": "01JW4KR347PV2MA9943TD38YQS",
      "workspaceId": "500",
      "name": "Free perfume sample",
      "status": "active",
      "description": "Try a free perfume sample with any order.",
      "type": "freeSample",
      "imageURL": "https://antavo.com",
      "priority": 1,
      "currency": "EUR",
      "stackingConfiguration": {
        "selfStackingConfiguration": {
          "isAllowed": false,
          "limit": 0
        },
        "stackingType": "exclusive",
        "excludedPromotionIds": null
      },
      "applicationsResetSchedule": null,
      "restriction": {
        "timeRestriction": {
          "start": "2025-01-01 22:55",
          "end": "2025-12-31 22:55",
          "recurringSchedule": null
        },
        "applicationsCountLimit": 0,
        "minTotalBeforeTax": "100",
        "maxTotalBeforeTax": "",
        "storeRestriction": {
          "stores": [],
          "storeGroups": [
            "Germany",
            "Austria"
          ]
        },
        "freeSample": {
          "products": [],
          "categories": [
            {
              "categoryId": "Perfumes",
              "quantity": 1
            }
          ],
          "itemMatchingRule": "any"
        }
      },
      "discount": {
        "freeSample": {
          "productId": "87654",
          "quantity": 1,
          "value": "0.00"
        }
      }
    },
    {
      "id": "01JW4M2FS0CX9DQETDV142JB4M",
      "workspaceId": "500",
      "name": "Sneakers promotional price",
      "status": "active",
      "description": "Sneakers at €70 during promotion.",
      "type": "promotionalPricing",
      "imageURL": "https://antavo.com",
      "priority": 1,
      "currency": "EUR",
      "stackingConfiguration": {
        "selfStackingConfiguration": {
          "isAllowed": false,
          "limit": 0
        },
        "stackingType": "stackable",
        "excludedPromotionIds": null
      },
      "applicationsResetSchedule": null,
      "restriction": {
        "timeRestriction": {
          "start": "2025-07-01 23:01",
          "end": "2025-07-31 23:01",
          "recurringSchedule": null
        },
        "applicationsCountLimit": 0,
        "minTotalBeforeTax": "",
        "maxTotalBeforeTax": "",
        "storeRestriction": {
          "stores": [],
          "storeGroups": [
            "Austria"
          ]
        },
        "promotionalPricing": {
          "productIds": [],
          "categoryIds": [
            "Apparel & Accessories > Clothing > Shoes > Sneakers"
          ]
        }
      },
      "discount": {
        "promotionalPricing": {
          "unitPriceBeforeTax": "70.00"
        }
      }
    }
  ]
}
  • GET /api/v1/promotions/{promotionId}: Fetch details and conditions of a specific promotion.
GET /api/v1/promotions/{promotionId} HTTP/1.1
Host: promotion.{environment}.antavo.com
Authorization: Bearer YOUR_ACCESS_TOKEN

The ID of the promotion should be provided as a path parameter. Replace environment with the name of the environment you currently use, and YOUR_ACCESS_TOKEN with the token provided by the authentication endpoint.

Example response

{
  "id": "01JVYEHFT9559EHVCMF3WPNNER",
  "workspaceId": "500",
  "name": "Denim 3+1",
  "status": "archived",
  "description": "Denim 3+1",
  "type": "bonusProducts",
  "imageURL": "https://antavo.com",
  "priority": 1,
  "currency": "EUR",
  "stackingConfiguration": {
    "selfStackingConfiguration": {
      "isAllowed": true,
      "limit": 2
    },
    "stackingType": "exclusive",
    "excludedPromotionIds": null
  },
  "applicationsResetSchedule": null,
  "restriction": {
    "timeRestriction": {
      "start": "2025-05-01 13:29",
      "end": "2025-05-10 13:29",
      "recurringSchedule": null
    },
    "applicationsCountLimit": 0,
    "minTotalBeforeTax": "10",
    "maxTotalBeforeTax": "14",
    "storeRestriction": {
      "stores": [
        "5077595177C60923"
      ],
      "storeGroups": [
        "Germany",
        "Austria"
      ]
    },
    "bonusProducts": {
      "products": [],
      "categories": [
        {
          "categoryId": "Apparel & Accessories > Clothing > Pants",
          "quantity": 3
        }
      ],
      "itemMatchingRule": "any"
    }
  },
  "discount": {
    "bonusProducts": {
      "products": [
        {
          "productId": "2235462",
          "quantity": 1
        }
      ],
      "value": "50.00"
    }
  }
}

Update Promotion Status

Updating the status of a promotion is a critical step in managing its lifecycle. This step controls when a promotion is editable, when it goes live, and when it is permanently archived.

Promotion statuses:

  • Draft status: The promotion is still being configured or edited ot have not been activated yet.
  • Active status: The promotion configuration is finalized, the promotion should be live and applicable to user carts.
  • Archived status: The promotion is permanently disabled. Once archived, the promotion cannot be reactivated.

The promotion status can be updated both via the Promotion Engine UI and programmatically through the POST /api/v1/promotion/{promotionId}/status endpoint. For automated workflows or integration purposes, the API endpoint allows you to update the lifecycle status of a promotion.

Example request

POST /api/v1/promotions/{promotionId}/status HTTP/1.1
Host: promotion.{environment}.antavo.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

{
	"status": "active"
  }

The ID of the promotion should be provided as a path parameter. Replace environment with the name of the environment you currently use, and YOUR_ACCESS_TOKEN with the token provided by the authentication endpoint.

Set the desired promotion status by providing the status field in the request body.

Example response

{
  "status": "success",
  "metadata": [],
  "payload": []
}

You can find a detailed description of the endpoint in the API reference.

Cart Submission for Promotion Calculation

The core of the Promotion Engine usage is submitting the current cart state for evaluation.

Using the POST /cart endpoint, you can:

  • Calculate which promotions apply based on cart contents and conditions.
  • Retrieve detailed information about matched promotions, including discounts applied, adjusted unit prices, tax adjustments, and total discount values.
  • Re-submit the same cartId multiple times to dynamically recalculate applicable promotions as the cart gets updated.
  • For promotions with usage limitations, the system temporarily reserves usage on the promotion.
    This means that the system treats those promotions as tentatively used, locking them for the given cart to prevent overuse or conflicts. These locks are valid for a limited period and are automatically released if the cart is not submitted to the /v1/checkout endpoint within that time.

This endpoint submits the cart data to trigger promotion and discount calculations, returning the updated pricing and promotional details in the response. It is particularly useful in checkout flows, where promotions must reflect the latest cart state, and for validating promotion logic before finalizing the order.

Example request

{
  "promotionSelectionStrategy": "biggestDiscount",
  "promotionApplicationMethod": "automatic",
  "rounding": "mathematical",
  "precision": 2,
  "cart": {
    "cartItems": [
      {
        "productId": 8675645322,
        "productCategoryId": "Apparel & Accessories > Clothing > Shoes > Sneakers",
        "quantity": 1,
        "unitPriceBeforeTax": 200,
        "tax": 40
      }
    ]
  },
  "cartId": 66512,
  "storeId": "47847307C1652044",
  "storeGroupId": "GreaterLondon",
  "customerId": "280e674c-c4ea-4a30-987a-d9267d1a5018",
  "promoCode": "PROMO10",
  "currency": "USD"
}

You can find a detailed description of all body parameters in the API reference.

Example response

{
  "status": "success",
  "metadata": [],
  "payload": {
    "cartId": "66512",
    "workspaceId": "500",
    "storeId": "5077595177C60923",
    "storeGroupId": "Austria",
    "customerId": "280e674c-c4ea-4a30-987a-d9267d1a5018",
    "timezone": "Europe/Budapest",
    "promotionSelectionStrategy": "biggestDiscount",
    "promotionApplicationMethod": "automatic",
    "rounding": "mathematical",
    "precision": 2,
    "promoCode": "PROMO10",
    "currency": "EUR",
    "cartItems": [
      {
        "productId": "8675645322",
        "productCategoryId": "Apparel & Accessories > Clothing > Shoes > Sneakers",
        "quantity": "1.000",
        "unitPriceBeforeTax": "200.00",
        "tax": "40.00"
      }
    ],
    "discounts": [
      {
        "promotionId": "01JW4M2FS0CX9DQETDV142JB4M",
        "promotionMetaData": {
          "name": "Sneakers promotional price",
          "description": "Sneakers at €70 during promotion.",
          "type": "promotionalPricing"
        },
        "discountType": "itemDiscount",
        "discountedItems": [
          {
            "productId": "8675645322",
            "productCategoryId": "Apparel & Accessories > Clothing > Shoes > Sneakers",
            "quantity": "1.000",
            "unitPriceBeforeTax": "70.00",
            "tax": "14.00"
          }
        ],
        "totalPriceBeforeTaxDiscount": "130.00",
        "taxDiscount": "26.00"
      }
    ]
  }
}

The API response includes the submitted cart along with a discounts array that lists all applicable promotions and their effects on pricing.

Checkout Submission to Finalize Promotion Application

Once the customer is ready to place an order, the final step is to submit the cart for checkout. This action finalizes any promotion calculations and sets their application.

Unlike the /v1/cart endpoint (which is primarily used for evaluation), the /v1/checkout endpoint marks the final application of the promotions. It is therefore a one-time operation per cartId and must be treated as the commit point in your transaction flow.

It’s not mandatory to call the /v1/cart endpoint before submitting to /v1/checkout. If you don’t need to preview promotions in advance (for example, if your flow doesn’t require showing discounts before finalizing the order, and application locking is not necessary), you can submit the cart directly to /v1/checkout for final evaluation and promotion application.

When you submit the cart to the /v1/checkout endpoint, the Promotion Engine will:

  • Re-evaluate the cart to determine all valid promotions at that moment.
  • Apply the final discounts, including item-level price changes, total cart discounts, and tax adjustments.
    Make sure to call this endpoint only when the cart is finalized, typically after the user has completed the payment or confirmed the order.
  • Finalize usage counts. If a promotion has an application limit, it will be incremented at this point.
  • Return a detailed breakdown of promotions applied, including promotion metadata, affected items and quantities, calculated price/tax savings, and total discounts applied.
  • End locking period. Any temporary locks created during earlier /cart calls will be resolved.

Example request

{
  "promotionSelectionStrategy": "biggestDiscount",
  "promotionApplicationMethod": "automatic",
  "rounding": "mathematical",
  "precision": 2,
  "cart": {
    "cartItems": [
      {
        "productId": 8675645322,
        "productCategoryId": "Apparel & Accessories > Clothing > Shoes > Sneakers",
        "quantity": 1,
        "unitPriceBeforeTax": 200,
        "tax": 40
      }
    ]
  },
  "cartId": 66512,
  "storeId": "47847307C1652044",
  "storeGroupId": "GreaterLondon",
  "customerId": "280e674c-c4ea-4a30-987a-d9267d1a5018",
  "promoCode": "PROMO10",
  "currency": "USD"
}

You can find a detailed description of all body parameters in the API reference. Cart contents should exactly reflect the final state of the order, as promotions will be applied based on this data.

Example response

{
  "status": "success",
  "metadata": [],
  "payload": {
    "cartId": "66512",
    "workspaceId": "500",
    "storeId": "5077595177C60923",
    "storeGroupId": "Austria",
    "customerId": "280e674c-c4ea-4a30-987a-d9267d1a5018",
    "timezone": "Europe/Budapest",
    "promotionSelectionStrategy": "biggestDiscount",
    "promotionApplicationMethod": "automatic",
    "rounding": "mathematical",
    "precision": 2,
    "promoCode": "PROMO10",
    "currency": "EUR",
    "cartItems": [
      {
        "productId": "8675645322",
        "productCategoryId": "Apparel & Accessories > Clothing > Shoes > Sneakers",
        "quantity": "1.000",
        "unitPriceBeforeTax": "200.00",
        "tax": "40.00"
      }
    ],
    "discounts": [
      {
        "promotionId": "01JW4M2FS0CX9DQETDV142JB4M",
        "promotionMetaData": {
          "name": "Sneakers promotional price",
          "description": "Sneakers at €70 during promotion.",
          "type": "promotionalPricing"
        },
        "discountType": "itemDiscount",
        "discountedItems": [
          {
            "productId": "8675645322",
            "productCategoryId": "Apparel & Accessories > Clothing > Shoes > Sneakers",
            "quantity": "1.000",
            "unitPriceBeforeTax": "70.00",
            "tax": "14.00"
          }
        ],
        "totalPriceBeforeTaxDiscount": "130.00",
        "taxDiscount": "26.00"
      }
    ]
  }
}

The API response includes the submitted cart along with a discounts array that lists all applicable promotions and their effects on pricing.

Error Handling and Responses

The Promotion Engine API provides clear HTTP status codes and structured error responses to help you diagnose and resolve issues effectively.

Each error response follows a consistent structure, typically returning a status, metadata, and a payload object containing details about the error.

Here is an example 400 error response provided by the /checkout endpoint:

{
  "status": "error",
  "error": {
    "type": "Validation error",
    "code": 577,
    "message": "The cart id field is required."
  }
}

Check the List of errors to browse all response codes.

We recommend that you log both the request and response when a call fails. This may help during debugging and when customers contact support. For automated workflows, implement fallback behavior (e.g., disabling promotion display or retrying after a cooldown) to avoid crashes or customer-facing errors.

Tips & Insights

When to use /checkout vs /cart

Use CaseRecommended Endpoint
Preview or simulate promotions during cart updates./cart
Temporarily reserve a promotion application until checkout is completed./cart
Finalize the cart, apply usage rules, and apply promotions./checkout

Calculation logic

When evaluating promotions, both via the /cart and /checkout endpoint, the engine applies a multi-step process to determine the optimal set of promotions for a cart:

  • Compatibility filtering: Promotions are filtered based on the cart and item restrictions, timing, stacking rules, and application limit rules configured using the Promotion Engine administration page.
  • Savings estimation: Each promotion's value is evaluated based on the current cart items according to discount configuration.
  • Valid configuration search: The engine explores combinations of promotions to identify the highest-value, valid configuration where the cart total remains non-negative.
  • Optimization constraints: If a combination leads to an invalid cart (e.g., negative total), certain promotion(s) will be discarded in favor of the best valid alternative.

This process ensures both performance and correctness, even when multiple overlapping promotions are applicable.

Promotion Calculator

You can use the Promotion Calculator to preview which promotions would apply to a given cart configuration. It works without calling any API endpoints, creating an order, or affecting usage limits.

The calculator simulates the logic of the /cart endpoint, but does not perform a real request or return an official response. It's useful for testing promotion setups or verifying rule configurations during development.


Did this page help you?