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

# Create metrics

> Create metrics.



## OpenAPI

````yaml https://admin.trophy.so/v1/openapi post /metrics
openapi: 3.1.0
info:
  title: Trophy
  version: 1.19.0
servers:
  - x-fern-server-name: Admin API
    url: https://admin.trophy.so/v1
    description: Admin API
security: []
paths:
  /metrics:
    servers:
      - url: https://admin.trophy.so/v1
        description: Admin API
    parameters:
      - $ref: '#/components/parameters/TenantId'
    post:
      tags:
        - Admin
      summary: Create metrics
      description: Create metrics.
      operationId: admin_metrics_create
      requestBody:
        description: Array of metrics to create. Maximum 100 metrics per request.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMetricsRequest'
            examples:
              Create number and currency metrics:
                value:
                  - name: Invites Sent
                    key: invites-sent
                  - name: Revenue
                    key: revenue
                    unitType: currency
                    units: USD
      responses:
        '200':
          description: Successful operation (no metrics created)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateMetricsResponse'
              examples:
                All requests had errors:
                  value:
                    created: []
                    issues:
                      - index: 0
                        severity: error
                        message: Name not a string
                      - index: 1
                        severity: error
                        message: Key already in use by another metric
        '201':
          description: Created (at least one metric created)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateMetricsResponse'
              examples:
                Success with no issues:
                  value:
                    created:
                      - id: 550e8400-e29b-41d4-a716-446655440000
                        name: Invites Sent
                        key: invites-sent
                        unitType: number
                        units: ''
                      - id: 550e8400-e29b-41d4-a716-446655440001
                        name: Revenue
                        key: revenue
                        unitType: currency
                        units: USD
                    issues: []
                Mixed success and errors:
                  value:
                    created:
                      - id: 550e8400-e29b-41d4-a716-446655440002
                        name: Signups
                        key: signups
                        unitType: number
                        units: ''
                    issues:
                      - index: 0
                        severity: error
                        message: Key already in use by another metric
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminErrorBody'
        '422':
          description: Unprocessible Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminErrorBody'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: javascript
          source: |
            import { TrophyApiClient } from '@trophyso/node';

            const trophy = new TrophyApiClient({
              apiKey: 'YOUR_API_KEY'
            });

            const response = await trophy.admin.metrics.create([
              {
                name: 'Invites Sent',
                key: 'invites-sent'
              },
              {
                name: 'Revenue',
                key: 'revenue',
                unitType: 'currency',
                units: 'USD'
              }
            ]);
        - lang: python
          source: |
            from trophy import TrophyApi

            client = TrophyApi(api_key='YOUR_API_KEY')

            response = client.admin.metrics.create([
              {
                "name": "Invites Sent",
                "key": "invites-sent"
              },
              {
                "name": "Revenue",
                "key": "revenue",
                "unitType": "currency",
                "units": "USD"
              }
            ])
        - lang: go
          source: >
            import (
              "context"

              api "github.com/trophyso/trophy-go"
              trophyclient "github.com/trophyso/trophy-go/client"
              "github.com/trophyso/trophy-go/option"
            )


            client := trophyclient.NewClient(
              option.WithApiKey("YOUR_API_KEY"),
            )


            response, err := client.Admin.Metrics.Create(context.TODO(),
            api.CreateMetricsRequest{})
components:
  parameters:
    TenantId:
      name: Tenant-ID
      in: header
      description: >-
        The tenant identifier for multi-tenant organisations. Required when the
        organisation has multi-tenancy enabled. Pass your own internal customer
        ID for the tenant. Ignored for single-tenant organisations.
      required: false
      schema:
        type: string
      example: customer_12345
  schemas:
    CreateMetricsRequest:
      title: CreateMetricsRequest
      type: array
      description: Request body for creating metrics.
      items:
        $ref: '#/components/schemas/CreateMetricRequestItem'
      minItems: 1
      maxItems: 100
    CreateMetricsResponse:
      title: CreateMetricsResponse
      type: object
      description: Response containing created metrics and any per-item issues.
      properties:
        created:
          type: array
          items:
            $ref: '#/components/schemas/CreatedMetric'
          description: Array of successfully created metrics.
        issues:
          type: array
          items:
            $ref: '#/components/schemas/AdminIssue'
          description: Array of issues encountered during metric creation.
      required:
        - created
        - issues
    AdminErrorBody:
      title: AdminErrorBody
      type: object
      properties:
        error:
          type: string
      required:
        - error
    CreateMetricRequestItem:
      title: CreateMetricRequestItem
      type: object
      description: A metric to create.
      properties:
        name:
          type: string
          description: The metric name.
          example: Invites Sent
        key:
          type: string
          pattern: ^[a-zA-Z\d-_]+$
          description: >-
            The metric key. Only alphanumeric characters, hyphens, and
            underscores are permitted.
          example: invites-sent
        unitType:
          type: string
          enum:
            - number
            - currency
          default: number
          description: The metric unit type. Defaults to `number`.
          example: currency
        units:
          type: string
          description: >-
            For `unitType: currency`, this must be a supported `MetricCurrency`
            code such as `USD`. For `number`, this is an optional freeform unit
            label.
          example: USD
      required:
        - name
        - key
    CreatedMetric:
      title: CreatedMetric
      type: object
      description: A successfully created metric returned from the create endpoint.
      properties:
        id:
          type: string
          format: uuid
          description: The UUID of the created metric.
        name:
          type: string
          description: The metric name.
        key:
          type: string
          description: The metric key.
        unitType:
          type: string
          enum:
            - number
            - currency
          description: The metric unit type.
        units:
          type: string
          description: The stored units value for the metric.
      required:
        - id
        - name
        - key
        - unitType
        - units
    AdminIssue:
      title: AdminIssue
      type: object
      description: An issue encountered while processing an item in an admin API request.
      properties:
        id:
          type: string
          description: The ID of the resource the issue relates to, when applicable.
          example: 550e8400-e29b-41d4-a716-446655440000
        userId:
          type: string
          description: The ID of the user the issue relates to, when applicable.
          example: user-123
        boostId:
          type: string
          description: The ID of the points boost the issue relates to, when applicable.
          example: 550e8400-e29b-41d4-a716-446655440000
        index:
          type: integer
          description: >-
            The zero-based index of the item the issue relates to, when no
            resource ID exists yet.
          example: 0
        severity:
          type: string
          enum:
            - error
            - warning
          description: The severity level of the issue.
          example: warning
        message:
          type: string
          description: A human-readable description of the issue.
          example: Would exceed maximum freeze limit
      required:
        - severity
        - message
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````