The limited-type metric (numeric type) is used to track user usage and prevent overconsumption.

The metric system integrates with the UniBee API, which provides event-based statistics.

You can report usage data by sending events to the Event API.

The metric counting for each product, you may need specified for the productId at Event API, default product will used if not specified

Aggregation Type of Count metric event, it increases 1 usage number

curl --location --request POST "$UniBee_API_Host/merchant/merchant_metric/merchant_metric_event" \
  --header "Authorization: Bearer $YOUR_API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "metricCode": "folder_count_limit", // code needs to be configured in advance in the UniBee portal
    "externalUserId": "$YOUR_USER_ID",
    "externalEventId": "string", // string, **unique**, e.m. [folderId]
    "metricProperties": {}
}'

same externalEventId , no double counting

Aggregation Type of Latest metric event, it Inspect 5, event of Latest type will not be add up

curl --location --request POST "$UniBee_API_Host/merchant/merchant_metric/merchant_metric_event" \
  --header "Authorization: Bearer $YOUR_API_KEY" \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "metricCode": "active_profile_limit", // code needs to be configured in advance in the UniBee portal
    "externalUserId": "$YOUR_USER_ID",
    "externalEventId": "string", // string, **unique**, e.m. [folderId]
    "metricProperties": {
      "active_profile": 5
    }
}'

if this metricCode is Aggregation Type of Sum, 5 will be add up to the current value

Normally, if the user has a subscription, the event interface returns the current value (based on the aggregation type) and the limit value for the user

{
  "code": 0,
  "message": "",
  "data": {
    "merchantMetricEvent": {
      "id": 15685,
      "merchantId": 15621,
      "metricCode": "active_profile_limit",
      "externalEventId": "req20240223yuUd7wHU7k8Cz2Fs",
      "createTime": 1708667871,
      "subscriptionIds": "sub202402236DygwtxKvLE1zN2",
      "subscriptionPeriodStart": 1708658304,
      "subscriptionPeriodEnd": 1708744704,
      "metricLimit": 5,
      "used": 2
    }
  },
  "redirect": "",
  "requestId": "req20240223DYIVhsEzTXykZEE"
}

When the user reaches the upper limit value set-up at Plan definision page, the event interface will return an error message (such as “reject”)to inform Multilogin that the usage has reached the upper limit.

{
  "code": 51,
  "message": "metric limit reached, current used: 10, limit: 10",
  "data": {},
  "redirect": "",
  "requestId": "req20240223rmNJQOnggAuYpPd"
}

All the metric value will be reset to 0 when the user’s subscription enters into the new billing cycle.

Event also can be revoked in the same subscription period by API UniBee API , and relative usage revoke yet.