---
title: "Get sales by product"
description: "Preorder units, orders, line revenue and last order date per variant (or product), as the dashboard's products table."
url: https://docs.stoqapp.com/v2-reference/preorders-reports/get-sales-by-product/
api: "API v2 reference"
method: GET
path: "/preorders/reports/products"
---

# Get sales by product

`GET https://app.stoqapp.com/api/v2/external/preorders/reports/products`

Preorder units, orders, line revenue and last order date per variant (or product), as the dashboard's products table.

**Note:** Counts preorder line items only (ordinary items in a mixed cart are excluded). revenue is line revenue. group_by=product rolls variants up to their product. range=all_time is the dashboard's All time. image_url is the variant's stored image, else the product's (null if none is stored).

## Query parameters

- `range` (string): Send all_time for the shop's whole history instead of a from/to window; from and to are then ignored. One of: `all_time`, `null`.
- `group_by` (string): Return one row per variant or per product. Default variant. One of: `variant`, `product`.
- `from` (string): Start of the window, as an ISO 8601 date or time. A bare date starts at midnight in the shop's time zone. Default 30 days ago.
- `to` (string): End of the window, as an ISO 8601 date or time. A bare date runs to the end of that day in the shop's time zone. Default today.
- `sort_by` (string): Column to sort the rows by. Default revenue; order_count is still accepted as an old name for orders. One of: `revenue`, `units_sold`, `orders`, `last_order_date`, `product_title`.
- `direction` (string): Sort order of the rows. Default desc. One of: `asc`, `desc`.
- `page` (integer): Page of rows to return, starting at 1.
- `per_page` (integer): Rows per page, 1 to 100. Default 25.

## Returns

- `window` (object, nullable): The date range the figures cover. Null when range is all_time.
  - `from` (string): Start of the range, ISO 8601.
  - `to` (string): End of the range, ISO 8601.
- `group_by` (string): e.g. `variant`
- `sort_by` (string): e.g. `revenue`
- `direction` (string): e.g. `desc`
- `currency` (null): ISO 4217 code of the currency the money amounts in this response are in: the order's for an order, else the shop's. Null when it is not known.
- `rows` (array of objects)
  - `shopify_product_id` (string): e.g. `gid://shopify/Product/8784906035384`
  - `product_title` (string): e.g. `Classic Sneaker`
  - `image_url` (string, nullable)
  - `shopify_variant_id` (string): e.g. `gid://shopify/ProductVariant/47284734423096`
  - `variant_title` (string): e.g. `Blue / Medium`
  - `sku` (string): e.g. `CS-BLU-M`
  - `units_sold` (integer)
  - `orders` (integer): e.g. `58`
  - `revenue` (string): e.g. `7040.00`
  - `last_order_date` (string): e.g. `2026-06-25T10:02:00Z`
- `meta` (object): Pagination for the list.
  - `total_count` (integer): Items matching the filters, across all pages.
  - `page` (integer): Page returned, starting at 1.
  - `per_page` (integer): Most items per page.
  - `total_pages` (integer): Pages available at this per_page; 0 when nothing matches.

Rate limit: this call costs 1 point ([rate limits](https://docs.stoqapp.com/docs/rate-limits/)).

## Examples

### Get sales by product

```sh
curl "https://app.stoqapp.com/api/v2/external/preorders/reports/products" \
  -H "X-Auth-Token: $STOQ_API_KEY"
```

### Get sales by product filtered by range, group_by and sort_by

```sh
curl "https://app.stoqapp.com/api/v2/external/preorders/reports/products?range=all_time&group_by=variant&sort_by=revenue" \
  -H "X-Auth-Token: $STOQ_API_KEY"
```

## 200

Success: example response shown.

```json
{
  "window": {
    "from": "2026-05-26T00:00:00Z",
    "to": "2026-06-25T23:59:59Z"
  },
  "group_by": "variant",
  "sort_by": "revenue",
  "direction": "desc",
  "currency": "USD",
  "rows": [
    {
      "shopify_product_id": "gid://shopify/Product/8784906035384",
      "product_title": "Classic Sneaker",
      "shopify_variant_id": "gid://shopify/ProductVariant/47284734423096",
      "variant_title": "Blue / Medium",
      "sku": "CS-BLU-M",
      "units": 64,
      "orders": 58,
      "revenue": "7040.00",
      "last_order_date": "2026-06-25T10:02:00Z"
    },
    {
      "shopify_product_id": "gid://shopify/Product/8784906035384",
      "product_title": "Classic Sneaker",
      "shopify_variant_id": "gid://shopify/ProductVariant/47284734455864",
      "variant_title": "Red / Large",
      "sku": "CS-RED-L",
      "units": 31,
      "orders": 30,
      "revenue": "3410.00",
      "last_order_date": "2026-06-24T18:40:00Z"
    }
  ],
  "meta": {
    "total_count": 42,
    "page": 1,
    "per_page": 25,
    "total_pages": 2
  }
}
```

## 401

Missing or invalid `X-Auth-Token`.

```json
{
  "errors": [
    "Invalid API key"
  ],
  "code": "auth_invalid",
  "details": [
    {
      "code": "auth_invalid",
      "message": "Invalid API key",
      "path": null,
      "value": null,
      "expected": null
    }
  ]
}
```

## 422

The request failed validation.

```json
{
  "errors": [
    "name is required"
  ],
  "code": "validation_failed",
  "details": [
    {
      "code": "validation_failed",
      "message": "name is required",
      "path": null,
      "value": null,
      "expected": null
    }
  ]
}
```

## 429

Rate limited: cost-weighted per token (read 1, write 2; 360 points / 60s). Check `Retry-After`.

```json
{
  "errors": [
    "Rate limit exceeded"
  ],
  "code": "rate_limited",
  "details": [
    {
      "code": "rate_limited",
      "message": "Rate limit exceeded",
      "path": null,
      "value": null,
      "expected": null
    }
  ]
}
```

