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

# Store an enrichment document as a draft

> Stores the document as a draft. Publish makes it live. A body equal to the live document drops its draft and returns `unchanged`.

The document `name` must match the URL. A body larger than 10 MB is `413`. Org admin only.



## OpenAPI

````yaml https://app-api.costory.io/docs/openapi.json put /enrichments/{name}
openapi: 3.0.0
info:
  title: Costory
  version: '1.0'
  description: API Documentation
servers:
  - url: ''
    description: Production server
security: []
paths:
  /enrichments/{name}:
    put:
      tags:
        - Enrichments
      summary: Store an enrichment document as a draft
      description: >-
        Stores the document as a draft. Publish makes it live. A body equal to
        the live document drops its draft and returns `unchanged`.


        The document `name` must match the URL. A body larger than 10 MB is
        `413`. Org admin only.
      operationId: saveEnrichmentDraft
      parameters:
        - schema:
            type: string
            description: Document name. Must match `name` in the body.
          required: true
          description: Document name. Must match `name` in the body.
          name: name
          in: path
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EnrichmentDocument'
            examples:
              merge:
                summary: Merge columns from a key
                description: >-
                  One key writes several columns. `merge` leaves a value the row
                  already has.
                value:
                  name: 02_namespace_to_org
                  description: >-
                    EKS pods the pod label does not resolve -> namespace's
                    responsible organization
                  keyField: cos_namespace
                  priority: 2
                  conditions: input.cos_cluster_name != null && input.cos_namespace != ""
                  targetColumns:
                    - name: owner_org
                      mode: merge
                    - name: owner_org_code
                      mode: merge
                  entries:
                    - key: team-a
                      then:
                        owner_org: Platform
                        owner_org_code: PLAT
              split:
                summary: Split the cost
                description: One key splits the billed row. The weights of `then` sum to 1.
                value:
                  name: 03_account_split
                  description: Split a shared account across the teams that use it
                  keyField: cos_account_id
                  priority: 3
                  targetColumns:
                    - name: owner_org
                      mode: merge
                  entries:
                    - key: '111122223333'
                      then:
                        - owner_org: Platform
                          weight: 0.6
                        - owner_org: Data
                          weight: 0.4
              datedReplace:
                summary: Replace inside a date window
                description: >-
                  The same key writes a different value in each window. Windows
                  for one key must not overlap. `replace` overwrites a value the
                  row already has.
                value:
                  name: 04_project_owner
                  description: Project owner changed on 1 July 2024
                  keyField: cos_project_id
                  priority: 4
                  targetColumns:
                    - name: owner_org
                      mode: replace
                  entries:
                    - key: billing-prod
                      when:
                        start: '2024-01-01'
                        end: '2024-06-30'
                      then:
                        owner_org: Finance
                    - key: billing-prod
                      when:
                        start: '2024-07-01'
                      then:
                        owner_org: Platform
              metric:
                summary: Split from a metric table
                description: >-
                  One key splits each day's cost from a BigQuery measure.
                  `integrationId` is an active BigQuery integration.
                  `propagates` names the target columns the metric table fills.
                value:
                  name: 05_shared_ml_platform
                  description: Split a shared platform by daily CPU hours
                  keyField: cos_feature
                  priority: 5
                  targetColumns:
                    - name: app
                      mode: replace
                    - name: team
                      mode: replace
                    - name: cost_center
                      mode: replace
                  entries:
                    - key: shared-ml-platform
                      then:
                        integrationId: clx8f2k9a0001qw3h7bn2m5vz
                        metric:
                          table: >-
                            costory-prod.example_metrics.shared_ml_platform_usage
                          dateColumn: date
                          metricColumn: cpu_hours
                        propagates:
                          - app
                          - team
                          - cost_center
      responses:
        '200':
          description: Draft stored
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnrichmentDraftWriteResponse'
        '400':
          description: The document is invalid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnrichmentErrors'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Unauthorized'
        '403':
          description: Org admin required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DimensionsAdminRequired'
        '413':
          description: Request body is larger than 10 MB
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnrichmentErrors'
      security:
        - bearerAuth: []
components:
  schemas:
    EnrichmentDocument:
      type: object
      properties:
        name:
          type: string
          description: Must match the name in the URL.
        description:
          type: string
        keyField:
          type: string
          description: Billing column whose value selects an entry.
        priority:
          type: integer
          minimum: 0
        conditions:
          type: string
          description: >-
            CEL expression. Every field is `input.` plus one SQL identifier.
            Omitted when unset.
        targetColumns:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
              mode:
                type: string
                enum:
                  - replace
                  - merge
            required:
              - name
              - mode
        entries:
          type: array
          items:
            type: object
            properties:
              key:
                type: string
                description: Value of `keyField` this entry matches.
              when:
                type: object
                properties:
                  start:
                    type: string
                    description: Inclusive start, YYYY-MM-DD.
                  end:
                    type: string
                    description: Inclusive end, YYYY-MM-DD.
                description: Optional date window. Set start, end, or both.
              then:
                anyOf:
                  - type: object
                    additionalProperties:
                      anyOf:
                        - type: string
                        - type: number
                        - nullable: true
                          type: string
                          enum:
                            - null
                    description: >-
                      Column values this entry writes. `weight` is the share of
                      the billed row and defaults to 1.
                  - type: array
                    items:
                      type: object
                      additionalProperties:
                        anyOf:
                          - type: string
                          - type: number
                          - nullable: true
                            type: string
                            enum:
                              - null
                      description: >-
                        Column values this entry writes. `weight` is the share
                        of the billed row and defaults to 1.
                  - $ref: '#/components/schemas/EnrichmentMetricThen'
                description: >-
                  One allocation, several when the entry splits the cost, or a
                  metric then.
            required:
              - key
              - then
      required:
        - name
        - keyField
        - priority
        - targetColumns
        - entries
    EnrichmentDraftWriteResponse:
      type: object
      properties:
        change:
          type: string
          enum:
            - added
            - changed
            - removed
            - unchanged
      required:
        - change
    EnrichmentErrors:
      type: object
      properties:
        errors:
          type: array
          items:
            type: string
      required:
        - errors
    Unauthorized:
      type: object
      properties:
        error:
          type: string
          description: Unauthorized error message
      required:
        - error
    DimensionsAdminRequired:
      type: object
      properties:
        error:
          type: string
          enum:
            - ADMIN_REQUIRED
      required:
        - error
    EnrichmentMetricThen:
      type: object
      properties:
        integrationId:
          type: string
          description: Active BigQuery integration of this organization.
        metric:
          type: object
          properties:
            table:
              type: string
              description: BigQuery table as project.dataset.table.
            dateColumn:
              type: string
            metricColumn:
              type: string
          required:
            - table
            - dateColumn
            - metricColumn
        propagates:
          type: array
          items:
            type: string
          description: Target columns filled from the metric table.
      required:
        - integrationId
        - metric
        - propagates
      description: >-
        Split the billed row by a daily BigQuery measure instead of static
        weights.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT or Clerk ak_* API key
      description: >-
        Send `Authorization: Bearer <credential>` using either a Clerk session
        JWT or a Clerk API key (`ak_*`). API keys may identify a user (`user_*`)
        or organization (`org_*`) principal and are generated in the Clerk
        Dashboard under API keys.

````

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