{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/reportingninja-com/json-schema/reportingninja-com-calculated-metrics-update-request-schema.json",
  "title": "CalculatedMetricsUpdateRequest",
  "description": "Which calculated metric to change and what of it. Everything the body does not carry is left as it is, inside the block of its kind too. integration_id, type and level are accepted only when they name what the metric already is. The keys a read publishes and a write has no column for -- integration, is_system_defined, not_expressible_reason and not_expressible_message -- are declared here as readOnly: they are accepted, ignored and named one by one in a READ_ONLY_FIELD_IGNORED warning, so what a read answered can be sent straight back with nothing taken out of it. A null means \"leave it as it is\".",
  "x-generated": "2026-11-23",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/reportingninja-com-openapi.json#/components/schemas/CalculatedMetricsUpdateRequest",
  "type": "object",
  "required": [
    "calculated_metric_key"
  ],
  "additionalProperties": false,
  "properties": {
    "calculated_metric_key": {
      "type": "string",
      "description": "The metric to change. From /v1/calculated-metrics/list."
    },
    "name": {
      "minLength": 2,
      "maxLength": 50,
      "description": "How the definition is listed in the account. 2 to 50 characters, with no character above the Basic Multilingual Plane.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "display_name": {
      "minLength": 2,
      "maxLength": 50,
      "description": "What is drawn on a widget that uses it. Null or left out leaves it as it is.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "internal_notes": {
      "maxLength": 250,
      "description": "A note for the account's own staff, at most 250 characters. An empty string takes it away.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "integration_id": {
      "description": "Only the integration the metric already has.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "level": {
      "description": "Only the data view the metric already has.",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "type": {
      "type": "string",
      "enum": [
        "expression",
        "function",
        "filtered"
      ],
      "description": "Only the kind the metric already is."
    },
    "expression": {
      "anyOf": [
        {
          "type": "object",
          "description": "Kind expression: the formula and how its result is printed.",
          "additionalProperties": false,
          "properties": {
            "format": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "none",
                "time",
                "currency",
                "percentage",
                null
              ],
              "description": "Required on a creation. The two older values a read may publish, time_millis and text, are kept by an update that does not name format and cannot be written."
            },
            "formula": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "string"
              },
              "description": "A flat list of infix tokens: metric ids of /v1/fields for this integration, the operators + - * /, '(' and ')', and literal numbers. At least one metric, the parentheses balance, and an id the field catalogue does not publish is refused -- which is stricter than the application, where a token is a metric as soon as it starts with the prefix of an integration."
            },
            "green_when_increases": {
              "type": "boolean",
              "description": "Whether a rise of the metric is drawn as a good thing. True on a creation that does not name it."
            }
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "The block of the expression kind. Null, or left out, in a metric of another kind -- which is what a read publishes for it."
    },
    "function": {
      "anyOf": [
        {
          "type": "object",
          "description": "Kind function: one metric aggregated over a period.",
          "additionalProperties": false,
          "properties": {
            "metric": {
              "description": "A metric id of /v1/fields for this integration.",
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "function": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "average",
                "min",
                "max",
                null
              ]
            },
            "time_period": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "day",
                "week",
                "month",
                null
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "The block of the function kind. Null, or left out, in a metric of another kind."
    },
    "filtered": {
      "anyOf": [
        {
          "type": "object",
          "description": "Kind filtered: one metric read through a saved filter of the same integration.",
          "additionalProperties": false,
          "properties": {
            "metric": {
              "description": "A metric id of /v1/fields for this integration.",
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            },
            "filter_key": {
              "description": "A saved filter of the account and of this integration. From /v1/filters/list.",
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        {
          "type": "null"
        }
      ],
      "description": "The block of the filtered kind. Null, or left out, in a metric of another kind."
    },
    "connection_key": {
      "type": "string",
      "description": "Only for facebook_ads and ga4, together with account_id: the connection of the account whose own fields the definition uses, the custom conversions of a Meta ad account or the custom metrics of a GA4 property, as /v1/fields publishes them with include_custom_fields. A formula may then name the count and the value of each custom conversion (not its cost per conversion) or each custom metric (not the averages). The pair is not stored: the metric is offered for any account or property that has every one of the fields it uses. From /v1/connections."
    },
    "account_id": {
      "type": "string",
      "description": "Only for facebook_ads and ga4, together with connection_key: the ad account or the GA4 property whose own fields the definition uses. From /v1/connections."
    },
    "integration": {
      "type": "string",
      "readOnly": true,
      "description": "The name of a data source this API publishes no integration_id for, which a read answers instead of integration_id. Published by /v1/calculated-metrics/get and written by nothing. It is accepted here so the object a read answers can be sent straight back as a body; the key is ignored and the answer carries a READ_ONLY_FIELD_IGNORED warning naming it."
    },
    "is_system_defined": {
      "type": "boolean",
      "readOnly": true,
      "description": "Published by /v1/calculated-metrics/get and written by nothing. It is accepted here so the object a read answers can be sent straight back as a body; the key is ignored and the answer carries a READ_ONLY_FIELD_IGNORED warning naming it."
    },
    "not_expressible_reason": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "readOnly": true,
      "description": "Published by /v1/calculated-metrics/get and written by nothing. It is accepted here so the object a read answers can be sent straight back as a body; the key is ignored and the answer carries a READ_ONLY_FIELD_IGNORED warning naming it."
    },
    "not_expressible_message": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "readOnly": true,
      "description": "Published by /v1/calculated-metrics/get and written by nothing. It is accepted here so the object a read answers can be sent straight back as a body; the key is ignored and the answer carries a READ_ONLY_FIELD_IGNORED warning naming it."
    },
    "dry_run": {
      "type": "boolean",
      "description": "Validate everything and write nothing."
    },
    "idempotency_key": {
      "type": "string",
      "description": "Replays the answer of an identical call for 24 hours."
    }
  }
}