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

# Get a templating operation

> Returns the state, progress, and result of an apply or clear run. Poll it until `done` is `true`.

Use the last segment of `operation.name` from [Apply a templating plan](https://docs.kodelabs.com/products/kode-api/api-reference/templating/apply-a-templating-plan.md) or [Clear a templating plan](https://docs.kodelabs.com/products/kode-api/api-reference/templating/clear-a-templating-plan.md) as the `operationId`. This response is the operation itself. It is not wrapped in `operation`.

`metadata.state` is one of:

* `QUEUED` and `RUNNING`: The run has not finished.
* `SUCCEEDED`: The run finished. `response` holds `matchedPoints` and `devicesAffected`.
* `FAILED`: The run stopped with an error. `error` holds the engine's `code` and `message`.
* `STALLED`: The run is `RUNNING` but has not reported progress for a while. It is not finished, so `done` stays `false`. KODE API works this state out when you read the operation.

`metadata.progress` is a percentage that updates after each batch. Do not use it to detect completion. Use `done`.

When the run is `SUCCEEDED`, graphics, device references, and device linking update in the background afterwards. They can lag behind the point data for a short time.


## OpenAPI

````yaml /openapi/kode-api.yaml get /api/v1/buildings/{buildingId}/templating/operations/{operationId}
openapi: 3.1.0
info:
  title: KODE API
  version: 1.0.0
  summary: Programmatic access to KODE OS resources and operations.
  description: >
    Use the KODE API to work with buildings, data sources, connectors, devices,
    points, virtual devices,

    timeseries data, schedules, the ontology, templating, mass writes, spaces,
    space assignments, tenants, meters, users, actions,

    and AssetOps work orders.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.kodelabs.com/kodeos
    description: KODE API
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: OAuth 2.0 discovery, token, and revocation endpoints.
  - name: Buildings
    description: Buildings and their areas.
  - name: Data sources
    description: Data sources connected to a building.
  - name: Devices
    description: Devices and their points.
  - name: Points
    description: Point queries and point writes.
  - name: Timeseries
    description: Current and historical point values.
  - name: Actions
    description: Actions exposed by building data sources.
  - name: Work orders
    description: AssetOps work orders, lookups, comments, and attachments.
  - name: Connectors
    description: KODE API connectors and the devices and points ingested through them.
  - name: Schedules
    description: Schedules discovered on building data sources.
  - name: Templating
    description: Apply ontology templates to groups of points.
  - name: Virtual devices
    description: Virtual devices that group points from other devices.
  - name: Ontology
    description: Canonical types, fields, units, and connections of the KODE ontology.
  - name: Users
    description: Users of the organization and their app access.
  - name: Mass write
    description: Write values to many points across buildings, and follow each run.
  - name: Spaces
    description: Levels and space units of a building, and the meters located in them.
  - name: Space assignments
    description: Assign tenants to leasable spaces of a building for a period.
  - name: Tenants
    description: Tenants of a building, the people or companies that lease its spaces.
  - name: Meters
    description: >-
      Meters of a building, their space assignments, parent and child links, and
      readings.
paths:
  /api/v1/buildings/{buildingId}/templating/operations/{operationId}:
    get:
      tags:
        - Templating
      summary: Get a templating operation
      description: >-
        Returns the state, progress, and result of an apply or clear run. Poll
        it until `done` is `true`.
      operationId: getTemplatingOperation
      parameters:
        - $ref: '#/components/parameters/BuildingId'
        - description: The operation id.
          name: operationId
          in: path
          required: true
          schema:
            type: string
            pattern: '[^\p{C}\p{Z}]{1,128}'
        - description: >-
            Comma-separated top-level fields to return. One or more of `name`,
            `done`, `metadata`, `response`, and `error`. The default is every
            field. An unknown name returns `400`.
          name: fields
          in: query
          schema:
            type: string
      responses:
        '200':
          description: The operation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TemplatingOperationEnvelopePublic'
        '400':
          description: The `operationId` is not valid, or `fields` has an unknown name.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: >-
            The service account lacks permission to view templating, or the
            building does not exist or is not assigned to it. KODE API answers
            `403` in both cases so that building ids cannot be probed.
        '404':
          description: No operation with this id exists in this building.
        '429':
          $ref: '#/components/responses/TooManyRequests'
components:
  parameters:
    BuildingId:
      name: buildingId
      in: path
      required: true
      description: Building identifier from List buildings.
      schema:
        type: string
      example: 67c960faffaa42223163099e
  schemas:
    TemplatingOperationEnvelopePublic:
      type: object
      properties:
        name:
          type: string
          description: Operation resource name.
          examples:
            - >-
              buildings/66f1a2b3c4d5e6f7a8b9c0d1/templating/operations/66f1a2b3c4d5e6f7a8b9c0d3
        done:
          type: boolean
          description: Whether the operation has finished (successfully or not).
          examples:
            - false
        metadata:
          $ref: '#/components/schemas/Metadata3'
          description: Progress and identifying metadata, always present.
          type: object
        response:
          $ref: '#/components/schemas/Response1'
          description: Present only once done and successful.
          type: object
        error:
          $ref: '#/components/schemas/Error1'
          description: Present only once done and failed.
          type: object
    Metadata3:
      type: object
      properties:
        operation:
          $ref: '#/components/schemas/TemplatingOperationPublic'
          description: Which verb started this operation.
          type: string
          examples:
            - APPLY
        canonicalType:
          type: string
          description: Canonical type this run is scoped to.
          examples:
            - AHU
        state:
          $ref: '#/components/schemas/TemplatingRunStatePublic'
          description: Run state. STALLED is derived on read, never stored.
          type: string
          examples:
            - RUNNING
        progress:
          type: number
          format: double
          description: >-
            Progress as a percentage, 0-100, updated after each batch. Use done,
            not progress, to detect completion.
          examples:
            - 62.5
        createdAt:
          $ref: '#/components/schemas/Date'
          description: When the run was created.
          type: string
        updatedAt:
          $ref: '#/components/schemas/Date'
          description: When the run was last updated.
          type: string
        actorId:
          type: string
          description: The calling service account's id.
          examples:
            - 66f1a2b3c4d5e6f7a8b9c0d4
        etag:
          type: string
          description: Etag of the resolved plan this run started from.
          examples:
            - sha256:9f86d081...
        requestId:
          type: string
          description: requestId this run was started with.
          examples:
            - 5f8a1b2c-3d4e-4f5a-8b6c-7d8e9f0a1b2c
    Response1:
      type: object
      properties:
        matchedPoints:
          type: integer
          format: int32
          description: Points matched and written by this run.
          examples:
            - 8120
        devicesAffected:
          type: integer
          format: int32
          description: Distinct devices affected by this run.
          examples:
            - 212
        notes:
          type: array
          items:
            type: string
          description: >-
            Run-level notices. On SUCCEEDED, states that downstream updates
            finish asynchronously.
    Error1:
      type: object
      properties:
        code:
          type: string
          description: Engine-reported error code.
          examples:
            - '13'
        message:
          type: string
          description: Engine-reported error message.
    TemplatingOperationPublic:
      type: string
      enum:
        - TEMPLATING_OPERATION_UNSPECIFIED
        - APPLY
        - CLEAR
    TemplatingRunStatePublic:
      type: string
      enum:
        - TEMPLATING_RUN_STATE_UNSPECIFIED
        - QUEUED
        - RUNNING
        - SUCCEEDED
        - FAILED
        - STALLED
    Date:
      type: string
      description: >-
        Date and time in UTC, with a numeric offset and no colon, for example
        `2026-10-28T13:51:31+0000`.
      examples:
        - 2026-10-28T13:51:31+0000
  responses:
    Unauthorized:
      description: The access token is missing, invalid, or expired. Request a new token.
    TooManyRequests:
      description: >-
        A rate-limit window is exhausted. Wait, then retry with increasing
        delays.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        Paste an access token from [Create an access
        token](/products/kode-api/api-reference/authentication/create-an-access-token).
        Tokens expire, so request a new one if you receive `401`.

````

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