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

# Create Draft Metric

> Create a metric in the workspace draft



## OpenAPI

````yaml post /v2/api/projects/{projectId}/workspaces/{workspaceId}/draft/metrics
openapi: 3.1.0
info:
  title: Upsolve API
  version: 1.5.0
servers:
  - url: https://api.upsolve.ai
security: []
tags: []
paths:
  /v2/api/projects/{projectId}/workspaces/{workspaceId}/draft/metrics:
    post:
      summary: Create a metric in the workspace draft
      description: Create a metric in the workspace draft
      operationId: PostV2ApiProjectsProjectIdWorkspacesWorkspaceIdDraftMetrics
      parameters:
        - name: projectId
          in: path
          required: true
          description: The project the workspace belongs to.
          schema:
            type: string
            format: uuid
            pattern: >-
              ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$
            description: The project the workspace belongs to.
        - name: workspaceId
          in: path
          required: true
          description: The workspace (data model) id.
          schema:
            type: string
            format: uuid
            pattern: >-
              ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$
            description: The workspace (data model) id.
      requestBody:
        description: >-
          POST /v2/api/projects/:projectId/workspaces/:workspaceId/draft/metrics
          Request body
        content:
          application/json:
            schema:
              type: object
              properties:
                apiKey:
                  type: string
                  minLength: 1
                  description: >-
                    Upsolve API key, generated under Account → Developer
                    settings in the Upsolve Hub. Keys are user-scoped: pass
                    organizationId alongside the key to select which org to act
                    on.
                  examples:
                    - up_embed_************
                organizationId:
                  description: >-
                    Your Upsolve organization's UUID — the org that owns the API
                    key and project. This is NOT a project organization: do not
                    pass a value registered via /projects/register-organization,
                    and do not pass an `externalId` (only
                    `projectOrganizationId` accepts those). Omit it when using
                    an org-bound API key — the org is read from the key and any
                    value sent here is ignored. Required only for user-scoped
                    API keys (created under Account → Developer settings) and
                    for the Supabase JWT path, where the org is ambiguous and
                    membership is verified against it.
                  examples:
                    - 123e4567-e89b-12d3-a456-426614174000
                  type: string
                  format: uuid
                  pattern: >-
                    ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$
                slug:
                  description: The metric's handle. Derived from the name when absent.
                  type: string
                  minLength: 1
                  maxLength: 100
                  pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*$
                metric:
                  oneOf:
                    - type: object
                      properties:
                        name:
                          type: string
                          minLength: 1
                          maxLength: 200
                          description: The metric's display name.
                        description:
                          default: ''
                          description: >-
                            What the metric means, in business terms. Searched
                            by the agent alongside the name.
                          type: string
                          maxLength: 5000
                        format:
                          type: string
                          enum:
                            - number
                            - currency
                            - percent
                          description: >-
                            How the value is displayed: number, currency or
                            percent.
                        type:
                          type: string
                          const: simple
                        tableKey:
                          type: string
                          minLength: 1
                          maxLength: 500
                          description: >-
                            The catalog key (schema.table) of the table to
                            aggregate.
                        columnName:
                          type: string
                          minLength: 1
                          maxLength: 255
                          description: The column the aggregation reads.
                        aggregation:
                          type: string
                          enum:
                            - sum
                            - count
                            - count_distinct
                            - avg
                            - min
                            - max
                          description: sum, count, count_distinct, avg, min or max.
                        defaultFilters:
                          default: []
                          description: Conditions baked into the metric, ANDed together.
                          maxItems: 50
                          type: array
                          items:
                            type: object
                            properties:
                              column:
                                type: string
                                minLength: 1
                                maxLength: 255
                                description: A column of the metric's table.
                              operator:
                                type: string
                                enum:
                                  - eq
                                  - neq
                                  - gt
                                  - lt
                                  - in
                                  - not_in
                                description: eq, neq, gt, lt, in or not_in.
                              value:
                                anyOf:
                                  - anyOf:
                                      - type: string
                                        maxLength: 500
                                      - type: number
                                  - minItems: 1
                                    maxItems: 100
                                    type: array
                                    items:
                                      anyOf:
                                        - type: string
                                          maxLength: 500
                                        - type: number
                                description: >-
                                  A string or number; a non-empty list for in /
                                  not_in.
                            required:
                              - column
                              - operator
                              - value
                            additionalProperties: false
                      required:
                        - name
                        - format
                        - type
                        - tableKey
                        - columnName
                        - aggregation
                      additionalProperties: false
                    - type: object
                      properties:
                        name:
                          type: string
                          minLength: 1
                          maxLength: 200
                          description: The metric's display name.
                        description:
                          default: ''
                          description: >-
                            What the metric means, in business terms. Searched
                            by the agent alongside the name.
                          type: string
                          maxLength: 5000
                        format:
                          type: string
                          enum:
                            - number
                            - currency
                            - percent
                          description: >-
                            How the value is displayed: number, currency or
                            percent.
                        type:
                          type: string
                          const: ratio
                        numeratorMetricSlug:
                          type: string
                          minLength: 1
                          maxLength: 100
                          pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*$
                          description: The slug of the metric divided.
                        denominatorMetricSlug:
                          type: string
                          minLength: 1
                          maxLength: 100
                          pattern: ^[a-z0-9]+(?:-[a-z0-9]+)*$
                          description: The slug of the metric divided by.
                      required:
                        - name
                        - format
                        - type
                        - numeratorMetricSlug
                        - denominatorMetricSlug
                      additionalProperties: false
                    - type: object
                      properties:
                        name:
                          type: string
                          minLength: 1
                          maxLength: 200
                          description: The metric's display name.
                        description:
                          default: ''
                          description: >-
                            What the metric means, in business terms. Searched
                            by the agent alongside the name.
                          type: string
                          maxLength: 5000
                        format:
                          type: string
                          enum:
                            - number
                            - currency
                            - percent
                          description: >-
                            How the value is displayed: number, currency or
                            percent.
                        type:
                          type: string
                          const: derived
                        formula:
                          type: string
                          minLength: 1
                          maxLength: 2000
                          description: >-
                            Arithmetic over other metrics written as {slug},
                            e.g. ({revenue} - {cost}) / {revenue}. Numbers, + -
                            * / and parentheses only.
                      required:
                        - name
                        - format
                        - type
                        - formula
                      additionalProperties: false
                  description: The metric's definition.
                  discriminator:
                    propertyName: type
              required:
                - metric
            examples:
              example1:
                value:
                  apiKey: up_embed_************
                  organizationId: 123e4567-e89b-12d3-a456-426614174000
        required: true
      responses:
        '201':
          description: >-
            POST
            /v2/api/projects/:projectId/workspaces/:workspaceId/draft/metrics
            Positive response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    const: success
                  data:
                    type: object
                    properties:
                      metric:
                        type: object
                        properties:
                          definition:
                            oneOf:
                              - type: object
                                properties:
                                  slug:
                                    type: string
                                  name:
                                    type: string
                                  description:
                                    type: string
                                  format:
                                    type: string
                                    enum:
                                      - number
                                      - currency
                                      - percent
                                  type:
                                    type: string
                                    const: simple
                                  tableKey:
                                    type: string
                                  columnName:
                                    type: string
                                  aggregation:
                                    type: string
                                    enum:
                                      - sum
                                      - count
                                      - count_distinct
                                      - avg
                                      - min
                                      - max
                                  defaultFilters:
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        column:
                                          type: string
                                        operator:
                                          type: string
                                          enum:
                                            - eq
                                            - neq
                                            - gt
                                            - lt
                                            - in
                                            - not_in
                                        value:
                                          anyOf:
                                            - type: string
                                            - type: number
                                            - type: array
                                              items:
                                                anyOf:
                                                  - type: string
                                                  - type: number
                                      required:
                                        - column
                                        - operator
                                        - value
                                      additionalProperties: false
                                required:
                                  - slug
                                  - name
                                  - description
                                  - format
                                  - type
                                  - tableKey
                                  - columnName
                                  - aggregation
                                  - defaultFilters
                                additionalProperties: false
                              - type: object
                                properties:
                                  slug:
                                    type: string
                                  name:
                                    type: string
                                  description:
                                    type: string
                                  format:
                                    type: string
                                    enum:
                                      - number
                                      - currency
                                      - percent
                                  type:
                                    type: string
                                    const: ratio
                                  numeratorMetricSlug:
                                    type: string
                                  denominatorMetricSlug:
                                    type: string
                                required:
                                  - slug
                                  - name
                                  - description
                                  - format
                                  - type
                                  - numeratorMetricSlug
                                  - denominatorMetricSlug
                                additionalProperties: false
                              - type: object
                                properties:
                                  slug:
                                    type: string
                                  name:
                                    type: string
                                  description:
                                    type: string
                                  format:
                                    type: string
                                    enum:
                                      - number
                                      - currency
                                      - percent
                                  type:
                                    type: string
                                    const: derived
                                  formula:
                                    type: string
                                  referencedMetricSlugs:
                                    type: array
                                    items:
                                      type: string
                                required:
                                  - slug
                                  - name
                                  - description
                                  - format
                                  - type
                                  - formula
                                  - referencedMetricSlugs
                                additionalProperties: false
                            description: The metric as the working copy holds it.
                            discriminator:
                              propertyName: type
                          baseMetricVersion:
                            type:
                              - integer
                              - 'null'
                            minimum: -9007199254740991
                            maximum: 9007199254740991
                          hasPendingEdits:
                            type: boolean
                            description: >-
                              Edited since the last publish, or never published
                              at all.
                          lockVersion:
                            type: integer
                            minimum: -9007199254740991
                            maximum: 9007199254740991
                            description: >-
                              Send this back on a patch or delete; a stale one
                              is rejected.
                          updatedBy:
                            type:
                              - string
                              - 'null'
                          updatedAt:
                            type:
                              - string
                              - 'null'
                          createdAt:
                            type:
                              - string
                              - 'null'
                          problem:
                            type:
                              - string
                              - 'null'
                        required:
                          - definition
                          - baseMetricVersion
                          - hasPendingEdits
                          - lockVersion
                          - updatedBy
                          - updatedAt
                          - createdAt
                          - problem
                        additionalProperties: false
                    required:
                      - metric
                    additionalProperties: false
                required:
                  - status
                  - data
                additionalProperties: false
        '400':
          description: >-
            POST
            /v2/api/projects/:projectId/workspaces/:workspaceId/draft/metrics
            Negative response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    const: error
                  error:
                    type: object
                    properties:
                      message:
                        type: string
                      code:
                        type: string
                      details:
                        type: object
                        propertyNames:
                          type: string
                        additionalProperties: {}
                    required:
                      - message
                    additionalProperties: false
                required:
                  - status
                  - error
                additionalProperties: false
      security:
        - APIKEY_1: []
components:
  securitySchemes:
    APIKEY_1:
      type: apiKey
      in: query
      name: apiKey
      x-in-actual: body
      description: apiKey MUST be supplied within the request body instead of query

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.