> ## Documentation Index
> Fetch the complete documentation index at: https://docs.unibee.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Query User History Limit Metric By Invoice (History Query Mode, limit_metered and limit_recurring only)

## Endpoint Overview

**GET** `https://api.unibee.dev/merchant/metric/user/history/metric_by_invoice`

Query User History Limit Metric By Invoice (History Query Mode, limit\_metered and limit\_recurring only)

***

## Authorization

All UniBee Merchant API requests require authentication via API key.

| Header          | Required | Description                           |
| --------------- | -------- | ------------------------------------- |
| `Authorization` | Yes      | Bearer `<your_api_key>`               |
| `Content-Type`  | Yes      | `application/json` (for request body) |

***

## Parameters

Parameters for this endpoint are listed below. The schema is also shown in the Try it panel.

### Query parameters

| Name        | Type   | Required | Description              |
| ----------- | ------ | -------- | ------------------------ |
| `invoiceId` | string | Yes      | The unique id of invoice |

***

## Request examples

### cURL

```bash theme={null}
curl -X GET "https://api.unibee.dev/merchant/metric/user/history/metric_by_invoice" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"
```

### Sandbox

```bash theme={null}
curl -X GET "https://api-sandbox.unibee.top/merchant/metric/user/history/metric_by_invoice" \
  -H "Authorization: Bearer YOUR_SANDBOX_API_KEY" \
  -H "Content-Type: application/json"
```

***

## Response

Success responses return a JSON envelope with `code`, `data`, `message`, `redirect`, and `requestId`. `code` `0` indicates success.

| Field                      | Type    | Description                                                                                                                                      |
| -------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `code`                     | integer | Response code. `0` = success                                                                                                                     |
| `data`                     | object  | Response payload                                                                                                                                 |
| `data.isLatestPaidInvoice` | boolean | True when current-metric path was used (queried invoice is the subscription's latest paid invoice), false when snapshot or history path was used |
| `data.userHistoryMetric`   | object  |                                                                                                                                                  |
| `message`                  | string  | Human-readable message                                                                                                                           |
| `requestId`                | string  | Request ID for support                                                                                                                           |

***

## Error handling

| HTTP status | Meaning                                                                   |
| ----------- | ------------------------------------------------------------------------- |
| 400         | Bad request — invalid or missing parameters. Check `message` in the body. |
| 401         | Unauthorized — missing or invalid API key.                                |
| 404         | Not found — invalid path or resource.                                     |
| 500         | Server error — retry with backoff.                                        |

When `code` in the response body is non-zero, check `message` for details. Use `requestId` when contacting support.


## OpenAPI

````yaml get /merchant/metric/user/history/metric_by_invoice
openapi: 3.0.0
info:
  description: UniBee Api Server
  license:
    name: Apache-2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  title: OpenAPI UniBee
  version: daily,buildtime:202603161017
servers:
  - url: https://api.unibee.dev
  - url: https://api-sandbox.unibee.top
security:
  - Authorization: []
paths:
  /merchant/metric/user/history/metric_by_invoice:
    get:
      tags:
        - User Metric
      summary: >-
        Query User History Limit Metric By Invoice (History Query Mode,
        limit_metered and limit_recurring only)
      parameters:
        - description: The unique id of invoice
          in: query
          name: invoiceId
          required: true
          schema:
            description: The unique id of invoice
            format: string
            properties: {}
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  code:
                    format: int
                    properties: {}
                    type: integer
                  data:
                    properties:
                      isLatestPaidInvoice:
                        description: >-
                          True when current-metric path was used (queried
                          invoice is the subscription's latest paid invoice),
                          false when snapshot or history path was used
                        format: bool
                        properties: {}
                        type: boolean
                      userHistoryMetric:
                        $ref: >-
                          #/components/schemas/unibee.api.bean.detail.UserHistoryMetric
                    type: object
                  merchantId:
                    format: int64
                    properties: {}
                    type: integer
                  message:
                    format: string
                    properties: {}
                    type: string
                  redirect:
                    format: string
                    properties: {}
                    type: string
                  requestId:
                    format: string
                    properties: {}
                    type: string
                type: object
          description: ''
components:
  schemas:
    unibee.api.bean.detail.UserHistoryMetric:
      properties:
        invoiceId:
          description: Invoice ID
          format: string
          properties: {}
          type: string
        limitStats:
          description: Limit metric stats (limit_metered and limit_recurring only)
          format: '[]*detail.UserHistoryMetricLimitStat'
          items:
            $ref: >-
              #/components/schemas/unibee.api.bean.detail.UserHistoryMetricLimitStat
          properties: {}
          type: array
      type: object
    unibee.api.bean.detail.UserHistoryMetricLimitStat:
      properties:
        maxEventId:
          description: MaxEventId
          format: int64
          properties: {}
          type: integer
        metricLimit:
          $ref: '#/components/schemas/unibee.api.bean.detail.PlanMetricLimitDetail'
        minEventId:
          description: MinEventId
          format: int64
          properties: {}
          type: integer
        totalLimit:
          description: TotalLimit
          format: int64
          properties: {}
          type: integer
        usedValue:
          description: UsedValue
          format: int64
          properties: {}
          type: integer
      type: object
    unibee.api.bean.detail.PlanMetricLimitDetail:
      properties:
        MerchantId:
          format: int64
          properties: {}
          type: integer
        MetricId:
          format: int64
          properties: {}
          type: integer
        PlanLimits:
          format: '[]*detail.MerchantMetricPlanLimitDetail'
          items:
            $ref: >-
              #/components/schemas/unibee.api.bean.detail.MerchantMetricPlanLimitDetail
          properties: {}
          type: array
        TotalLimit:
          format: int64
          properties: {}
          type: integer
        UserId:
          format: int64
          properties: {}
          type: integer
        aggregationProperty:
          description: aggregation property
          format: string
          properties: {}
          type: string
        aggregationType:
          description: 0-count，1-count unique, 2-latest, 3-max, 4-sum
          format: int
          properties: {}
          type: integer
        code:
          description: code
          format: string
          properties: {}
          type: string
        metricName:
          description: metric name
          format: string
          properties: {}
          type: string
        quotaAdjustments:
          description: Quota adjustments (carryover + manual)
          format: '[]*detail.MetricLimitQuotaDetail'
          items:
            $ref: '#/components/schemas/unibee.api.bean.detail.MetricLimitQuotaDetail'
          properties: {}
          type: array
        type:
          description: >-
            1-limit_metered，2-charge_metered,3-charge_recurring,4-limit_recurring
          format: int
          properties: {}
          type: integer
      type: object
    unibee.api.bean.detail.MerchantMetricPlanLimitDetail:
      properties:
        createTime:
          description: create utc time
          format: int64
          properties: {}
          type: integer
        gmtModify:
          description: update time
          format: int64
          properties: {}
          type: integer
        id:
          description: id
          format: int64
          properties: {}
          type: integer
        merchantId:
          description: merchantId
          format: int64
          properties: {}
          type: integer
        merchantMetric:
          $ref: '#/components/schemas/unibee.api.bean.MerchantMetric'
        metricId:
          description: metricId
          format: int64
          properties: {}
          type: integer
        metricLimit:
          description: plan metric limit
          format: int64
          properties: {}
          type: integer
        planId:
          description: plan_id
          format: int64
          properties: {}
          type: integer
        quantity:
          description: quantity for this plan
          format: int64
          properties: {}
          type: integer
      type: object
    unibee.api.bean.detail.MetricLimitQuotaDetail:
      properties:
        adjustmentTime:
          description: adjustment time (for manual)
          format: int64
          properties: {}
          type: integer
        id:
          format: int64
          properties: {}
          type: integer
        merchantMemberEmail:
          description: operator email (for manual)
          format: string
          properties: {}
          type: string
        merchantMemberId:
          description: operator id (for manual)
          format: int64
          properties: {}
          type: integer
        previousPeriodLimit:
          description: previous period limit (for carryover)
          format: int64
          properties: {}
          type: integer
        previousPeriodUsed:
          description: previous period used (for carryover)
          format: int64
          properties: {}
          type: integer
        quotaAmount:
          description: quota amount
          format: int64
          properties: {}
          type: integer
        quotaType:
          description: carryover or manual
          format: string
          properties: {}
          type: string
        reason:
          description: reason/note
          format: string
          properties: {}
          type: string
      type: object
    unibee.api.bean.MerchantMetric:
      properties:
        aggregationProperty:
          description: aggregation property
          format: string
          properties: {}
          type: string
        aggregationType:
          description: 1-count，2-count unique, 3-latest, 4-max, 5-sum
          format: int
          properties: {}
          type: integer
        archived:
          description: archived
          format: bool
          properties: {}
          type: boolean
        carryoverProrationEnabled:
          description: Enable carryover proration for this metric (false when not set)
          format: bool
          properties: {}
          type: boolean
        code:
          description: code
          format: string
          properties: {}
          type: string
        createTime:
          description: create utc time
          format: int64
          properties: {}
          type: integer
        gmtModify:
          description: update time
          format: int64
          properties: {}
          type: integer
        id:
          description: id
          format: int64
          properties: {}
          type: integer
        merchantId:
          description: merchantId
          format: int64
          properties: {}
          type: integer
        metaData:
          additionalProperties:
            $ref: '#/components/schemas/interface'
          description: meta_data(json)
          format: map[string]interface {}
          properties: {}
          type: object
        metricDescription:
          description: metric description
          format: string
          properties: {}
          type: string
        metricName:
          description: metric name
          format: string
          properties: {}
          type: string
        prorationRefundEnabled:
          description: >-
            Enable proration refund for this metric, i.e. reclaim metric limit
            on upgrade (false when not set)
          format: bool
          properties: {}
          type: boolean
        type:
          description: 1-limit_metered，2-charge_metered,3-charge_recurring
          format: int
          properties: {}
          type: integer
        unit:
          description: unit
          format: string
          properties: {}
          type: string
      type: object
    interface:
      properties: {}
      type: object
  securitySchemes:
    Authorization:
      bearerFormat: JWT
      scheme: bearer
      type: http

````