# Statistics

> Base URL: `https://pos.pages.fm/api/v1`. Authenticate with the `api_key` query parameter.

## Order statistics

`GET /shops/{SHOP_ID}/analytics/sale`

Get order statistics

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |
| `since` | query | string (date-time) |  | Start date |
| `until` | query | string (date-time) |  | End date |
| `split_by[]` | query | string[] |  | Group statistics by one or more dimensions. Each value is a `<Table>.<field>` key. - `Time.hour` / `Time.day` / `Time.month` / `Time.year` — by date bucket - `Order.source` / `Order.order_sources` — by order source / account - `Order.status` — by order status code - `Order.warehouse_id` — by warehouse - `Order.post_id` — by Facebook post - `Order.partner_id` — by shipping carrier - `Order.marketplace_id` — by e-commerce marketplace - `Order.country_code` / `Order.province_id` / `Order.district_id` / `Order.commune_id` / `Order.region_filter` — by shipping geography - `Order.tag` — by order tag - `Order.is_wholesale` / `Order.is_livestream` — wholesale / livestream flag - `Order.livestream_manager_ids` — by livestream manager - `Order.total_price` — by order total price bucket - `Order.ads_or_normal` / `Order.ad_account_id` / `Order.ad_id` — ad partitioning - `User.id` / `User.sale_group` / `User.department_id` — by staff / sale group / department - `Customer.id` / `Customer.level_id` / `Customer.new` — by customer / level / new vs. old - `Variation.id` / `Variation.product_id` — by variation / product - `Variation.category` / `Variation.supplier` / `Variation.brand_id` / `Variation.tag` — by product taxonomy - `Variation.price_range` / `Variation.quantity_range` — by product price/quantity bucket - `Variation.upsale` / `Variation.quantity` — upsell flag / sold quantity - `UTM.p_utm_source` / `UTM.p_utm_campaign` / `UTM.p_utm_medium` / `UTM.p_utm_term` / `UTM.p_utm_content` — by UTM tag - `Promotion.default` / `Promotion.advance` / `Promotion.combo` — by promotion / combo - `Ads.ad_id` / `Ads.ad_set_id` / `Ads.ad_campaign_id` — by ad / ad set / campaign |
| `filter` | query | object |  | Filter applied to the order set. Object keyed by `<Table>.<field>`; each value is an array of strings. Append `_exclude` to a key to negate it (e.g. `Order.status_exclude`, `Variation.category_exclude`). Append `_and` to AND-combine multi-valued list filters (e.g. `Variation.tags_and`). Common keys: - `Variation.id` / `Variation.product_id` — by variation / product - `Variation.category` / `Variation.supplier` / `Variation.brand_id` / `Variation.brand` — by product taxonomy - `Variation.tag` / `Variation.tags` / `Variation.attribute` — by product tag / attribute - `Variation.price_range` / `Variation.quantity_range` / `Variation.quantity` — by product price/quantity - `Variation.upsale` / `Variation.one_time_product` / `Variation.is_bonus_product` / `Variation.product_price_of_zero` / `Variation.unlink_ecommerce` — flag filters - `Order.source` / `Order.source_exclude` / `Order.order_sources` — order source - `Order.status` — order status code - `Order.warehouse_id` / `Order.post_id` / `Order.partner_id` / `Order.shop_partner_id` / `Order.marketplace_id` — operational filters - `Order.country_code` / `Order.province_id` / `Order.district_id` / `Order.commune_id` / `Order.region_filter` / `Order.region_filter_phil` — shipping geography - `Order.tag` / `Order.is_wholesale` / `Order.is_livestream` / `Order.received_at_shop` / `Order.is_upsale_order` — order flags - `Order.total_price` / `Order.revenue` — by total/revenue bucket - `Order.ad_id` / `Order.ads_source` / `Order.ad_account_id` / `Order.ads_or_normal` — ads filters - `Order.order_currency` — order currency - `Order.id` / `Order.project` — by order id / project - `Order.p_utm_source` / `Order.p_utm_campaign` / `Order.p_utm_medium` / `Order.p_utm_term` / `Order.p_utm_content` / `Order.utm_affiliate` / `Order.link` — UTM filters - `Order.instant` / `Order.N24H` / `Order.GSGN` — service partner filters - `Order.livestream_manager_id` / `Order.livestream_manager_ids` — livestream manager - `User.id` / `User.sale_group` / `User.department_id` / `User.pke_mkter` / `User.assigning_seller_id` / `User.assigning_care_id` / `User.item_assign_seller_id` — staff filters - `Customer.id` / `Customer.level_id` / `Customer.gender` / `Customer.tag` / `Customer.conversation_tags` / `Customer.new` / `Customer.referral_code` — customer filters - `Promotion.default` / `Promotion.advance` / `Promotion.id` / `Promotion.combo` — promotion filters |
| `success_status` | query | string |  | Success status |
| `success_record` | query | string |  | Success record |
| `user_type` | query | string |  | User type |
| `returned_record` | query | string |  | Returned record |
| `select_fields[]` | query | string[] |  | Select fields |

### Responses

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "Time.day": "2020-07-22",
      "returned": null,
      "success": {
        "cod": 1710000,
        "discount": 0,
        "order_count": 3,
        "price": 1800000,
        "product_count": 18,
        "shipping_fee": 0,
        "custom_formula_d6ae-ad02-be3d-b26e-3f65-d497-33c4": 1000000
      }
    },
    {
      "Time.day": "2020-07-27",
      "returned": null,
      "success": {
        "cod": 570000,
        "discount": 0,
        "order_count": 1,
        "price": 600000,
        "avg_price": 600000,
        "product_count": 6,
        "shipping_fee": 0,
        "custom_formula_d6ae-ad02-be3d-b26e-3f65-d497-33c4": 1000000
      }
    },
    {
      "Time.day": "2020-07-28",
      "returned": null,
      "success": {
        "cod": 5130000,
        "discount": 0,
        "order_count": 9,
        "price": 5400000,
        "avg_price": 600000,
        "product_count": 54,
        "shipping_fee": 0,
        "custom_formula_d6ae-ad02-be3d-b26e-3f65-d497-33c4": 1200000
      }
    },
    {
      "Time.day": "2020-07-30",
      "returned": null,
      "success": {
        "cod": 570000,
        "discount": 0,
        "order_count": 1,
        "price": 600000,
        "avg_price": 600000,
        "product_count": 6,
        "shipping_fee": 0,
        "custom_formula_d6ae-ad02-be3d-b26e-3f65-d497-33c4": 1200000
      }
    }
  ]
}
```

## List of customized formulas

`GET /shops/{SHOP_ID}/analytics/get_list_formula`

Get list of customized formulas

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |

### Responses

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "formula": "{price} - {shipping_fee}",
      "id": "0ea7-bc72-ae51-0769-a7c9-ca34-fff6",
      "name": "tien hang - phi ship",
      "unit": "currency"
    },
    {
      "formula": "{revenue} + {transfer_money}",
      "id": "3db3-72a7-c426-066a-4eed-a63b-be49",
      "name": "doanh thu + ck$",
      "unit": "currency"
    }
  ]
}
```

## List of analytic fields

`GET /shops/{SHOP_ID}/analytics/get_analytic_fields`

Get list of analytic fields

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |

### Responses

- `200` Success (object)

```json
{
  "success": true,
  "data": [
    {
      "id": "price",
      "name": "Tiền hàng"
    },
    {
      "id": "avg_price",
      "name": "Giá bán trung bình"
    },
    {
      "id": "shipping_fee",
      "name": "Phí VC thu của khách",
      "description": "Tiền vận chuyển thu của khách."
    },
    {
      "id": "discount",
      "name": "Chiết khấu",
      "description": "Tổng số tiền giảm giá trên từng sản phẩm."
    },
    {
      "id": "product_count",
      "name": "SL bán thực",
      "description": "Hàng bán ra đã trừ SL hoàn/đổi trả"
    },
    {
      "id": "close_rate",
      "name": "Tỷ lệ chốt",
      "description": "Số đơn chốt / (Tổng số đơn - SL đơn xoá)."
    },
    {
      "id": "commissions",
      "name": "Hoa hồng",
      "description": "Hoa hồng cho nhân viên, có thể cài đặt trong phần cấu hình."
    }
  ]
}
```

## List of custom statistic folders

`GET /shops/{SHOP_ID}/statistic_custom/folders`

Get list of custom statistic folders and their report items (folder_items). Each folder groups related custom reports configured for the shop (e.g. revenue, orders, products, finance, debts).

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `SHOP_ID` | path | integer | yes | Shop ID |

### Responses

- `200` Success (object)

```json
{
  "success": true,
  "folders": [
    {
      "name": "OtherReports",
      "label": "Báo cáo khác",
      "order": -1,
      "shop_id": 4,
      "creator_id": null,
      "last_editor_id": null,
      "can_remove": false,
      "is_removed": null,
      "setting": null,
      "total_price_ranges": null,
      "inserted_at": "2024-02-26T08:21:01",
      "updated_at": "2024-02-26T08:21:01",
      "folder_items": [
        {
          "id": "9d80f8b9-1c68-4026-81e6-70ed2381d360",
          "name": "pages.shop.statistic.salesStatistics",
          "label": "Doanh số",
          "description": null,
          "folder_name": "employee",
          "parent_id": null,
          "order": 0,
          "shop_id": 4,
          "creator_id": null,
          "last_editor_id": null,
          "can_remove": false,
          "is_removed": null,
          "attributes": null,
          "fields": [
            "total_order_count",
            "order_count",
            "price",
            "shipping_fee",
            "discount",
            "capital",
            "product_count"
          ],
          "filter": null,
          "children": [],
          "charts": null,
          "compare_ranges": {
            "chart": "bar-chart",
            "field": "product_count",
            "ranges": [
              {
                "range": "7"
              },
              {
                "range": "-7"
              }
            ]
          },
          "fill_color": false,
          "setting": {
            "returned_record": "success_record",
            "success_record": "inserted_at",
            "success_status": 0,
            "user_type": "assign"
          },
          "sort_by_field": null,
          "time_range": [
            "90"
          ],
          "users_can_see": null,
          "inserted_at": "2024-02-26T08:21:01",
          "updated_at": "2024-02-26T08:21:01"
        }
      ]
    },
    {
      "name": "Revenue",
      "label": "Báo cáo doanh thu",
      "order": 1,
      "shop_id": 4,
      "creator_id": null,
      "last_editor_id": null,
      "can_remove": false,
      "is_removed": null,
      "setting": null,
      "total_price_ranges": null,
      "inserted_at": "2023-09-20T03:01:25",
      "updated_at": "2023-09-20T03:01:25",
      "folder_items": [
        {
          "id": "9783d2e9-d973-4f6f-a735-f5883f4e678f",
          "name": "commons.time",
          "label": "Thời gian",
          "description": null,
          "folder_name": "Revenue",
          "parent_id": null,
          "order": 0,
          "shop_id": 4,
          "creator_id": null,
          "last_editor_id": null,
          "can_remove": false,
          "is_removed": null,
          "attributes": [
            "Variation.product_id"
          ],
          "fields": [
            "success_order_count",
            "returned_order_count",
            "price",
            "sales",
            "revenue",
            "capital",
            "profit"
          ],
          "filter": [],
          "children": [],
          "charts": [
            {
              "field": "success_order_count",
              "top": "all",
              "type": "bar-chart",
              "width": 100
            }
          ],
          "compare_ranges": {
            "chart": "bar-chart",
            "field": "profit",
            "ranges": [
              {
                "range": "7"
              },
              {
                "range": "-7"
              }
            ]
          },
          "fill_color": false,
          "setting": {
            "returned_record": "success_record",
            "success_record": "updated_at",
            "success_status": 1,
            "user_type": "update"
          },
          "sort_by_field": {
            "multi": [
              {
                "columnKey": "product_count",
                "field": "product_count",
                "order": "descend"
              }
            ]
          },
          "time_range": [
            "30"
          ],
          "users_can_see": null,
          "inserted_at": "2023-09-20T03:01:25",
          "updated_at": "2026-05-05T04:33:58"
        }
      ]
    }
  ]
}
```
