---
title: "Create Or Update Calculated Field (saveCalculatedField)"
method: POST
path: "/api/calculatedField"
tags: ["calculated-field-controller"]
---

# Create Or Update Calculated Field (saveCalculatedField)

`POST /api/calculatedField`

Creates or Updates the Calculated Field. When creating calculated field, platform generates Calculated Field Id as [time-based UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_(date-time_and_MAC_address)). The newly created Calculated Field Id will be present in the response. Specify existing Calculated Field Id to update the calculated field. Referencing non-existing Calculated Field Id will cause 'Not Found' error. Remove 'id', 'tenantId' from the request body example (below) to create new Calculated Field entity. 

Available for users with 'TENANT_ADMIN' or 'CUSTOMER_USER' authority.

## Request body

- CalculatedField
  - `id` CalculatedFieldId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'CALCULATED_FIELD', required — string
  - `createdTime` integer — Timestamp of the calculated field creation, in milliseconds
  - `tenantId` TenantId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'TENANT', required — string
  - `entityId` EntityId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'TENANT' | 'CUSTOMER' | 'USER' | 'DASHBOARD' | 'ASSET' | 'DEVICE' | 'ALARM' | 'RULE_CHAIN' | 'RULE_NODE' | 'ENTITY_VIEW' | 'WIDGETS_BUNDLE' | 'WIDGET_TYPE' | 'TENANT_PROFILE' | 'DEVICE_PROFILE' | 'ASSET_PROFILE' | 'API_USAGE_STATE' | 'TB_RESOURCE' | 'OTA_PACKAGE' | 'EDGE' | 'RPC' | 'QUEUE' | 'NOTIFICATION_TARGET' | 'NOTIFICATION_TEMPLATE' | 'NOTIFICATION_REQUEST' | 'NOTIFICATION' | 'NOTIFICATION_RULE' | 'QUEUE_STATS' | 'OAUTH2_CLIENT' | 'DOMAIN' | 'MOBILE_APP' | 'MOBILE_APP_BUNDLE' | 'CALCULATED_FIELD' | 'JOB' | 'ADMIN_SETTINGS' | 'AI_MODEL' | 'API_KEY', required
  - `type` 'SIMPLE' | 'SCRIPT' | 'GEOFENCING' | 'ALARM' | 'PROPAGATION' | 'RELATED_ENTITIES_AGGREGATION' | 'ENTITY_AGGREGATION'
  - `name` string — User defined name of the calculated field.
  - `debugMode` boolean
  - `debugSettings` DebugSettings
    - `failuresEnabled` boolean — Debug failures.
    - `allEnabled` boolean — Debug All. Used as a trigger for updating debugAllUntil.
    - `allEnabledUntil` integer — Timestamp of the end time for the processing debug events.
  - `configurationVersion` integer — Version of calculated field configuration.
  - `configuration` SimpleCalculatedFieldConfiguration, required
    - `arguments` object, required
    - `expression` string
    - `output` union, required
      - AttributesOutput
        - `name` string
        - `scope` 'CLIENT_SCOPE' | 'SERVER_SCOPE' | 'SHARED_SCOPE'
        - `decimalsByDefault` integer
        - `strategy` union
          - AttributesImmediateOutputStrategy
            - `type` string, required
            - `sendAttributesUpdatedNotification` boolean
            - `updateAttributesOnlyOnValueChange` boolean
            - `saveAttribute` boolean
            - `sendWsUpdate` boolean
            - `processCfs` boolean
          - AttributesRuleChainOutputStrategy
            - `type` string, required
        - `type` string, required
      - TimeSeriesOutput
        - `name` string
        - `scope` 'CLIENT_SCOPE' | 'SERVER_SCOPE' | 'SHARED_SCOPE'
        - `decimalsByDefault` integer
        - `strategy` union
          - TimeSeriesImmediateOutputStrategy
            - `type` string, required
            - `ttl` integer
            - `saveTimeSeries` boolean
            - `saveLatest` boolean
            - `sendWsUpdate` boolean
            - `processCfs` boolean
          - TimeSeriesRuleChainOutputStrategy
            - `type` string, required
        - `type` string, required
    - `useLatestTs` boolean
  - `version` integer

## Response `200`

OK

- CalculatedField
  - `id` CalculatedFieldId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'CALCULATED_FIELD', required — string
  - `createdTime` integer — Timestamp of the calculated field creation, in milliseconds
  - `tenantId` TenantId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'TENANT', required — string
  - `entityId` EntityId
    - `id` string, uuid, required — ID of the entity, time-based UUID v1
    - `entityType` 'TENANT' | 'CUSTOMER' | 'USER' | 'DASHBOARD' | 'ASSET' | 'DEVICE' | 'ALARM' | 'RULE_CHAIN' | 'RULE_NODE' | 'ENTITY_VIEW' | 'WIDGETS_BUNDLE' | 'WIDGET_TYPE' | 'TENANT_PROFILE' | 'DEVICE_PROFILE' | 'ASSET_PROFILE' | 'API_USAGE_STATE' | 'TB_RESOURCE' | 'OTA_PACKAGE' | 'EDGE' | 'RPC' | 'QUEUE' | 'NOTIFICATION_TARGET' | 'NOTIFICATION_TEMPLATE' | 'NOTIFICATION_REQUEST' | 'NOTIFICATION' | 'NOTIFICATION_RULE' | 'QUEUE_STATS' | 'OAUTH2_CLIENT' | 'DOMAIN' | 'MOBILE_APP' | 'MOBILE_APP_BUNDLE' | 'CALCULATED_FIELD' | 'JOB' | 'ADMIN_SETTINGS' | 'AI_MODEL' | 'API_KEY', required
  - `type` 'SIMPLE' | 'SCRIPT' | 'GEOFENCING' | 'ALARM' | 'PROPAGATION' | 'RELATED_ENTITIES_AGGREGATION' | 'ENTITY_AGGREGATION'
  - `name` string — User defined name of the calculated field.
  - `debugMode` boolean
  - `debugSettings` DebugSettings
    - `failuresEnabled` boolean — Debug failures.
    - `allEnabled` boolean — Debug All. Used as a trigger for updating debugAllUntil.
    - `allEnabledUntil` integer — Timestamp of the end time for the processing debug events.
  - `configurationVersion` integer — Version of calculated field configuration.
  - `configuration` SimpleCalculatedFieldConfiguration, required
    - `arguments` object, required
    - `expression` string
    - `output` union, required
      - AttributesOutput
        - `name` string
        - `scope` 'CLIENT_SCOPE' | 'SERVER_SCOPE' | 'SHARED_SCOPE'
        - `decimalsByDefault` integer
        - `strategy` union
          - AttributesImmediateOutputStrategy
            - `type` string, required
            - `sendAttributesUpdatedNotification` boolean
            - `updateAttributesOnlyOnValueChange` boolean
            - `saveAttribute` boolean
            - `sendWsUpdate` boolean
            - `processCfs` boolean
          - AttributesRuleChainOutputStrategy
            - `type` string, required
        - `type` string, required
      - TimeSeriesOutput
        - `name` string
        - `scope` 'CLIENT_SCOPE' | 'SERVER_SCOPE' | 'SHARED_SCOPE'
        - `decimalsByDefault` integer
        - `strategy` union
          - TimeSeriesImmediateOutputStrategy
            - `type` string, required
            - `ttl` integer
            - `saveTimeSeries` boolean
            - `saveLatest` boolean
            - `sendWsUpdate` boolean
            - `processCfs` boolean
          - TimeSeriesRuleChainOutputStrategy
            - `type` string, required
        - `type` string, required
    - `useLatestTs` boolean
  - `version` integer

---

[API](https://skmtc.net/thingsboard/apis/thingsboard-rest-api.md) · [All operations](https://skmtc.net/thingsboard/apis/thingsboard-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/thingsboard/thingsboard-rest-api/revisions/40169ccdec5c/schema)
