OrdinateDB

Documentation

product Pre-releaseunwritten sections are marked
POST/v1/model/calc/rules

Create a calculation rule

operation ID: post_v1_model_calc_rules

Overview

Create a calculation rule. The model API describes assets, attributes, bindings, templates, views, registries, and governed changes that give series data its operational meaning.

When to use it

  • Use it when an application needs to create a calculation rule.
  • Use it when a modeling tool is building, governing, resolving, or inspecting the asset and attribute hierarchy.

Quick example

Set the base URL and replace generated identifiers or credentials with values from your installation.

cURL

curl --request POST \
  --url "$ORDINATE_URL/v1/model/calc/rules" \
  --header "Authorization: Bearer $ORDINATE_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "string",
    "scope": {
      "template_id": "00000000-0000-4000-8000-000000000001",
      "output_attr_def_id": "00000000-0000-4000-8000-000000000001"
    },
    "tier": "expression",
    "trigger": {
      "kind": "event"
    },
    "unit_check": "strict",
    "provisional": "block"
  }'

Expected output · 201

Created rule identity and version

Example 201 output

{
  "rule_id": "00000000-0000-4000-8000-000000000001",
  "version": 0
}

The cURL request sends the smallest contract-derived body and asks OrdinateDB to create a calculation rule. The documented 201 response is created rule identity and version.

How it works

Assets form the composition hierarchy, attributes describe values on those assets, and time-bounded bindings connect attributes to stored series.

Reference

Required capability
calc-author
Authorization scope
handler-resolved target

Parameters

No parameters.

Request body

application/json

declared_inferredbooleanoptional
expressionany ofoptional

any of

option 1

string

option 2

null
namestringrequired
provisionalstringrequired
reasonstringoptional
scopeone ofrequired

one of

option 1

output_attr_def_idstringrequired
format: uuid
template_idstringrequired
format: uuid
unknown fields rejected

option 2

asset_idstringrequired
format: uuid
output_attribute_idstringrequired
format: uuid
unknown fields rejected
tierstringrequired
triggerone ofrequired

one of

option 1

debounce_msany ofoptional

any of

option 1

integerformat: int64

option 2

null
kindstringrequired
unknown fields rejected

option 2

alignany ofrequired

Arbitrary JSON value

any of

option 1

object with arbitrary properties

option 2

array

any items

option 3

string

option 4

number

option 5

integer

option 6

boolean

option 7

null
interval_nsintegerrequired
format: int64
kindstringrequired
unknown fields rejected

option 3

edgestringrequired
exprstringrequired
kindstringrequired
unknown fields rejected
unit_checkstringrequired
whenany ofoptional

any of

option 1

string

option 2

null
unknown fields rejected

Example request body

{
  "name": "string",
  "scope": {
    "template_id": "00000000-0000-4000-8000-000000000001",
    "output_attr_def_id": "00000000-0000-4000-8000-000000000001"
  },
  "tier": "expression",
  "trigger": {
    "kind": "event"
  },
  "unit_check": "strict",
  "provisional": "block"
}

Responses

201Created rule identity and version

application/json

rule_idstringrequired
format: uuid
versionintegerrequired
format: int64
unknown fields rejected

Example 201 output

{
  "rule_id": "00000000-0000-4000-8000-000000000001",
  "version": 0
}
400Parse, dimension, reference, cycle, kind, or validation error

application/json

ErrorEnvelope
codestringrequired
correlation_idstringrequired
format: uuid
detailsobjectoptional
errorstringrequired

Example 400 output

{
  "error": "string",
  "code": "account-sealed",
  "correlation_id": "00000000-0000-4000-8000-000000000001"
}
401Authentication required

application/json

ErrorEnvelope
codestringrequired
correlation_idstringrequired
format: uuid
detailsobjectoptional
errorstringrequired

Example 401 output

{
  "error": "string",
  "code": "account-sealed",
  "correlation_id": "00000000-0000-4000-8000-000000000001"
}
403calc-author capability is not granted

application/json

ErrorEnvelope
codestringrequired
correlation_idstringrequired
format: uuid
detailsobjectoptional
errorstringrequired

Example 403 output

{
  "error": "string",
  "code": "account-sealed",
  "correlation_id": "00000000-0000-4000-8000-000000000001"
}
503Model database is not configured or unavailable

application/json

ErrorEnvelope
codestringrequired
correlation_idstringrequired
format: uuid
detailsobjectoptional
errorstringrequired

Example 503 output

{
  "error": "string",
  "code": "account-sealed",
  "correlation_id": "00000000-0000-4000-8000-000000000001"
}

Code examples

These examples are generated from the source contract. Replace the base URL, credentials, identifiers, and minimal generated values for your instance.

JavaScript

const ordinateUrl = "http://localhost:8080";
const token = "<bearer-token>";

const response = await fetch(`${ordinateUrl}/v1/model/calc/rules`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${token}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
  "name": "string",
  "scope": {
    "template_id": "00000000-0000-4000-8000-000000000001",
    "output_attr_def_id": "00000000-0000-4000-8000-000000000001"
  },
  "tier": "expression",
  "trigger": {
    "kind": "event"
  },
  "unit_check": "strict",
  "provisional": "block"
})
});

if (!response.ok) {
  throw new Error(`OrdinateDB returned ${response.status}: ${await response.text()}`);
}

const data = await response.json();
console.log(data);