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

# Get a metric by code



## OpenAPI

````yaml /api-reference/ubb_openapi_inline.json get /metrics/{metric_code}
openapi: 3.0.1
info:
  title: Usage Based Billing API
  version: 1.0.0
  description: An Orchestrator for Usage Based Billing and Payments
servers:
  - url: https://api-m.sandbox.paypal.com/v1/commerce/billing
security:
  - BearerAuth:
      - read
      - write
tags:
  - name: Alerts
    description: API endpoints for managing subscription alerts
  - name: Events
    description: API endpoints for managing events
  - name: Metrics
    description: API endpoints for metrics and usage data
  - name: Merchant Activation
    description: API endpoint for merchant activation
  - name: Credit Notes
    description: API endpoints for credit notes management
  - name: Customers
    description: API endpoints for customer management
  - name: Invoices
    description: API endpoints for invoice management
  - name: Plans
    description: API endpoints for subscription plans
  - name: Subscriptions
    description: API endpoints for subscriptions
  - name: Wallets
    description: API endpoints for wallet management
  - name: Taxes
    description: API endpoints for tax management
  - name: Billing Entities
    description: API endpoints for billing entities
  - name: Features
    description: API endpoints for managing features and privileges
  - name: Entitlements
    description: API endpoints for managing plan and subscription entitlements
paths:
  /metrics/{metric_code}:
    get:
      tags:
        - Metrics
      summary: Get a metric by code
      operationId: GetMetricByCode
      parameters:
        - $ref: '#/components/parameters/metric_code'
      responses:
        '200':
          description: Metric retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetricResponse'
              example:
                id: bm_01H2XT1G7N8E2JHJKBVPDS0TQD
                name: API Requests
                code: api_requests
                type: METERED
                description: Measures the total number of API requests made
                aggregation_type: COUNT
                field_filters:
                  - key: region
                    values:
                      - us-east-1
                      - us-west-1
                created_at: '2023-05-10T14:32:18Z'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    metric_code:
      name: metric_code
      in: path
      required: true
      description: The code of the metric
      schema:
        type: string
      example: Metric-Code-123
  schemas:
    MetricResponse:
      type: object
      required:
        - id
        - name
        - code
        - aggregation_type
        - created_at
      allOf:
        - $ref: '#/components/schemas/MetricBase'
        - type: object
          properties:
            id:
              type: string
              description: >-
                Unique identifier of the metric, automatically generated by the
                system upon creation. This ID is used internally to track the
                metric and cannot be modified.
            created_at:
              allOf:
                - $ref: '#/components/schemas/DateTimeWithZone'
              description: >-
                The date and time when the metric was created. ISO 8601 format
                with timezone.
            updated_at:
              allOf:
                - $ref: '#/components/schemas/DateTimeWithZone'
              description: >-
                The date and time when the metric was last updated. ISO 8601
                format with timezone.
    MetricBase:
      type: object
      properties:
        name:
          type: string
          description: >-
            Descriptive name of the metric that represents a pricing component
            of your application. This is primarily used for display purposes in
            the user interface.
        code:
          type: string
          description: >-
            Unique code used to identify the metric within your system. This
            code is used in API requests to associate events with the correct
            metric and must be unique across all metrics. Once created, this
            code cannot be changed.
        type:
          $ref: '#/components/schemas/MetricType'
        description:
          type: string
          description: >-
            Optional detailed description of the metric that provides additional
            context about what the metric measures and how it's used. This
            information is for internal use and helps document the purpose of
            the metric.
        aggregation_type:
          $ref: '#/components/schemas/MetricAggregationType'
        aggregation_field:
          type: string
          description: >-
            Property name within the event payload that will be used for
            aggregating usage data. This field specifies which value from the
            event should be used for calculations. It is required for
            aggregation types like 'SUM', 'MAX', and other types that operate on
            values, but not required for 'COUNT' aggregation.
        field_filters:
          type: array
          items:
            type: object
            properties:
              key:
                type: string
                description: >-
                  Property name within the event payload that will be used for
                  filtering. This allows you to segment usage data based on
                  specific event properties, such as region, tier, or any other
                  dimension you track.
              values:
                type: array
                items:
                  type: string
                description: >-
                  Array of specific values that the system should match against
                  the filter key. Only events with matching key-value pairs will
                  be included in the metric calculations. This enables
                  differentiated pricing based on dimensions like region,
                  environment, or other custom properties.
            required:
              - key
              - values
    DateTimeWithZone:
      type: string
      format: date-time
      description: Date and time in ISO 8601 format.
      example: '2023-10-01T12:00:00Z'
    Error:
      type: object
      properties:
        name:
          type: string
        debug_id:
          type: string
        message:
          type: string
        details:
          type: array
          items:
            $ref: '#/components/schemas/ErrorDetail'
    MetricType:
      type: string
      default: RECURRING
      enum:
        - METERED
        - RECURRING
      description: >-
        Type of metric, either 'metered' for usage-based or 'recurring' for
        fixed periodic charges.
      example: METERED
      x-enum-varnames:
        - METERED
        - RECURRING
      x-enum-descriptions:
        - Usage-based metric that charges based on the amount used.
        - Fixed periodic charge that recurs at specified intervals.
    MetricAggregationType:
      type: string
      nullable: true
      enum:
        - COUNT
        - SUM
        - MAX
        - COUNT_DISTINCT
        - LATEST
      x-enum-varnames:
        - COUNT
        - SUM
        - MAX
        - COUNT_DISTINCT
        - LATEST
      x-enum-descriptions:
        - Count the number of events
        - Sum the values of a numeric field
        - Find the maximum value of a numeric field
        - Count the number of distinct values
        - Use the latest value
      description: Aggregation type for the metric
      example: SUM
    ErrorDetail:
      type: object
      properties:
        field:
          type: string
        value:
          type: string
        location:
          type: string
        issue:
          type: string
        description:
          type: string
  responses:
    Forbidden:
      description: Authorization failed due to insufficient permissions.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            name: NOT_AUTHORIZED
            message: Authorization failed due to insufficient permissions.
            debug_id: 565f78f101498
            details:
              - issue: PERMISSION_DENIED
                description: >-
                  You do not have permission to access or perform operations on
                  this resource.
    NotFound:
      description: Resource Not Found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InternalServerError:
      description: Internal Server Error - An unexpected error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            name: INTERNAL_SERVER_ERROR
            message: An internal server error has occurred.
            debug_id: 90957fca61718
  securitySchemes:
    BearerAuth:
      type: oauth2
      description: >-
        Use the /v1/oauth2/token endpoint to obtain an access token and pass it
        as a Bearer token in the Authorization header.
      flows:
        clientCredentials:
          tokenUrl: https://api-m.sandbox.paypal.com/v1/oauth2/token
          scopes:
            read: Read access
            write: Write access

````