> ## Documentation Index
> Fetch the complete documentation index at: https://www.help.creatora.io/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> When building or modifying an integration with the Creatora API, start with https://www.help.creatora.io/en/api/build-with-ai.md. Retrieve the current GraphQL SDL from https://api.creatora.io/sdl before relying on API schema information.

# Measure sales using a coupon

> Report paid purchases and discounts recorded with a coupon code.

Measure paid purchases using a particular coupon during a period. Replace `WELCOME20` with your coupon code.

This example uses **September 1, 2026 at 00:00 UTC** (`1788220800000`) through **October 1, 2026 at 00:00 UTC**, exclusive (`1790812800000`). Replace both timestamps for your period and timezone. The request starts one millisecond earlier because the API date bounds are strict.

## Request

<RequestExample>
  ```graphql theme={null}
  {
    orders(couponCode: { equals: "WELCOME20" }, status: { equals: [succeeded] }, closedOn: { range: [1788220799999, 1790812800000] }) {
      id status closedOn amountNetCharge amountDiscountCoupon
      couponSnapshot { code }
      student { id email }
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Illustrative response theme={null}
  {
    "data": {
      "orders": [
        {
          "id": "55555555-5555-4555-8555-555555555555",
          "status": "succeeded",
          "closedOn": 1788224400000,
          "amountNetCharge": 80.0,
          "amountDiscountCoupon": 20.0,
          "couponSnapshot": {
            "code": "WELCOME20"
          },
          "student": {
            "id": "33333333-3333-4333-8333-333333333333",
            "email": "student@example.com"
          }
        }
      ]
    }
  }
  ```
</ResponseExample>

## Use the result

```javascript theme={null}
const start = 1788220800000;
const end = 1790812800000;
const sales = response.data.orders.filter(order =>
  order.status === "succeeded" && order.closedOn !== null &&
  order.closedOn >= start && order.closedOn < end && order.amountNetCharge > 0
);
const report = {
  purchases: sales.length,
  identifiedCustomers: new Set(sales.flatMap(order => order.student ? [order.student.id] : [])).size,
  amountCharged: Number(sales.reduce((sum, order) => sum + order.amountNetCharge, 0).toFixed(2)),
  couponDiscount: Number(sales.reduce((sum, order) => sum + order.amountDiscountCoupon, 0).toFixed(2))
};
```

The report measures recorded purchases and amounts associated with the coupon. Measuring conversion or the coupon’s effect on sales also requires visit and attribution data. Orders with a missing customer still contribute to purchase and amount totals.

The `closedOn` filter in the processing example selects completed purchases; the API date filter also returns Orders created in the period. The request has no list limit. For large reports, request shorter periods and deduplicate Orders by `id`. Amounts use the Platform currency. Manually registered Orders are included.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.