{
  "openapi": "3.0.4",
  "info": {
    "title": "Business Metrics Open API",
    "description": "",
    "version": "1.0"
  },
  "paths": {
    "/datacenter/v{version}/datasets": {
      "get": {
        "tags": [
          "DataSet"
        ],
        "summary": "GET all data sets",
        "description": "Returns all available data sets in the data center for a given portal. **Authorization policy**: datacenter:read. **Requires feature access**: UseDataCenter.",
        "parameters": [
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataSetOutputIEnumerableOpenApiResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    },
    "/datacenter/v{version}/datasets/{id}/values/period": {
      "get": {
        "tags": [
          "DataSet"
        ],
        "summary": "GET data set values for a period",
        "description": "Returns all values in a specified data set and for a specified time frame. **Authorization policy**: datacenter:read. **Requires feature access**: UseDataCenter.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Id of the data set for which data is to be returned",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Start of the time frame for which the data is to be returned. Use yyyy-MM-ddThh:mm format",
            "required": true,
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/LocalDateTime"
                }
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End of the time frame for which the data is to be returned. Use yyyy-MM-ddThh:mm format",
            "required": true,
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/LocalDateTime"
                }
              ]
            }
          },
          {
            "name": "sectionId",
            "in": "query",
            "description": "Id of the section for which data is to be returned",
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DataSetValueOutputIEnumerableOpenApiResponse"
                }
              }
            }
          },
          "409": {
            "description": "Data set with given id doesn't exist, or is not supported by Open API"
          },
          "429": {
            "description": "Too many requests"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      },
      "put": {
        "tags": [
          "DataSet"
        ],
        "summary": "PUT data set values for a period",
        "description": "Update data set values in a specified time frame.\nThis operation clears all existing values in the specified time frame for the specified data set, and inserts all provided values. **Authorization policy**: datacenter:create. **Requires feature access**: UseDataCenter.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Id of the data set for which data is to be replaced",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Start of the time frame in which the data is to be replaced. Use yyyy-MM-ddThh:mm format",
            "required": true,
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/LocalDateTime"
                }
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End of the time frame in which the data is to be replaced. Use yyyy-MM-ddThh:mm format",
            "required": true,
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/LocalDateTime"
                }
              ]
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DataSetValueInput"
                }
              }
            },
            "text/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DataSetValueInput"
                }
              }
            },
            "application/*+json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DataSetValueInput"
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "202": {
            "description": "Accepted"
          },
          "409": {
            "description": "Data set with given id doesn't exist, or validation failed for some values"
          },
          "429": {
            "description": "Too many requests"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    },
    "/datacenter/v{version}/datasets/{id}/values": {
      "put": {
        "tags": [
          "DataSet"
        ],
        "summary": "PUT data set values",
        "description": "Update data set values.\nThis operation creates new or replaces existing values in the specified data set. **Authorization policy**: datacenter:create. **Requires feature access**: UseDataCenter.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Id of the data set for which data is to be inserted or updated",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DataSetValueInput"
                }
              }
            },
            "text/json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DataSetValueInput"
                }
              }
            },
            "application/*+json": {
              "schema": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/DataSetValueInput"
                }
              }
            }
          },
          "required": true
        },
        "responses": {
          "202": {
            "description": "Accepted"
          },
          "409": {
            "description": "Data set with given id doesn't exist, or validation failed for some values"
          },
          "429": {
            "description": "Too many requests"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    },
    "/datacenter/v{version}/formulas": {
      "get": {
        "tags": [
          "Formula"
        ],
        "summary": "GET all available metrics",
        "description": "Returns a list of available metrics from the data center. **Authorization policy**: datacenter:read. **Requires feature access**: UseDataCenter.",
        "parameters": [
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FormulaOutputIEnumerableOpenApiResponse"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    },
    "/datacenter/v{version}/formulas/{id}/evaluate": {
      "get": {
        "tags": [
          "Formula"
        ],
        "summary": "GET evaluated metric values from the data center",
        "description": "Returns the evaluated values from a metric, for a specified time frame and department. **Authorization policy**: datacenter:read. **Requires feature access**: UseDataCenter.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Id of the formula for which data is to be returned",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "from",
            "in": "query",
            "description": "Start of the time frame for which the data is to be returned. Use yyyy-MM-dd format",
            "required": true,
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/LocalDate"
                }
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "description": "End of the time frame for which the data is to be returned. Use yyyy-MM-dd format",
            "required": true,
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/LocalDate"
                }
              ]
            }
          },
          {
            "name": "departmentId",
            "in": "query",
            "description": "Id of the department for which the data is to be returned.",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          },
          {
            "name": "version",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FormulaWithValuesOutputOpenApiResponse"
                }
              }
            }
          },
          "409": {
            "description": "Formula with given id doesn't exist, is not supported by Open API, or the period is invalid"
          },
          "429": {
            "description": "Too many requests"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CalendarSystem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "readOnly": true
          },
          "name": {
            "type": "string",
            "readOnly": true
          },
          "minYear": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "maxYear": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "eras": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Era"
            },
            "readOnly": true
          }
        },
        "additionalProperties": false
      },
      "DataSetOutput": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Id of the data set",
            "format": "int64"
          },
          "name": {
            "type": "string",
            "description": "Name of the data set"
          },
          "tag": {
            "type": "string",
            "description": "String identifier of the data set, used in formulas"
          },
          "unit": {
            "enum": [
              "Monetary",
              "HoursOfWork",
              "NumberOfPeople",
              "Percentage",
              "Other"
            ],
            "type": "string",
            "description": "Unit of data that can be inserted into metric"
          },
          "timeUnit": {
            "enum": [
              "Hourly",
              "Daily",
              "Weekly",
              "Monthly",
              "TimeBlocks"
            ],
            "type": "string",
            "description": "Unit of time that defines the level of granularity of the data inserted into metric (i.e. value per hour, value per day)"
          },
          "assignmentType": {
            "enum": [
              "Global",
              "Department",
              "Position",
              "Section"
            ],
            "type": "string",
            "description": "Setting that defines relation between data in the metric, and other entities in Planday (departments, positions)"
          },
          "departmentId": {
            "type": "integer",
            "description": "Applicable only if AssignmentType is set to Position or Section. Defines the department to which this metric is related to.",
            "format": "int64",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "DataSetOutputIEnumerableOpenApiResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DataSetOutput"
            },
            "description": "The response data.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Standard response wrapper for OpenAPI endpoints."
      },
      "DataSetValueInput": {
        "type": "object",
        "properties": {
          "value": {
            "type": "number",
            "description": "Numeric value itself",
            "format": "double"
          },
          "departmentId": {
            "type": "integer",
            "description": "Id of the related department. If the AssignmentType of the metric is \"Department\", \"Position\" or \"Section\" then this field is required.\nOtherwise it will be ignored",
            "format": "int64",
            "nullable": true
          },
          "positionId": {
            "type": "integer",
            "description": "Id of the related position. If the AssignmentType of the metric is \"Position\" then this field is required.\nOtherwise it will be ignored",
            "format": "int64",
            "nullable": true
          },
          "sectionId": {
            "type": "integer",
            "description": "Id of the related section. If the AssignmentType of the metric is \"Section\" then this field is required.\nOtherwise it will be ignored",
            "format": "int64",
            "nullable": true
          },
          "timeStamp": {
            "allOf": [
              {
                "$ref": "#/components/schemas/LocalDateTime"
              }
            ],
            "description": "Date and time of the occurrence of the value, in yyyy-MM-ddTHH:mm format. Must be between from and to dates, provided in request URL.\nIf the metric's TimeUnit is \"Daily\", then this value must be midnight.\nIf the metric's TimeUnit is \"Hourly\", then this value must be full hour."
          }
        },
        "additionalProperties": false
      },
      "DataSetValueOutput": {
        "type": "object",
        "properties": {
          "dataSetId": {
            "type": "integer",
            "description": "Id of the related data set",
            "format": "int64"
          },
          "value": {
            "type": "number",
            "description": "Numeric value itself",
            "format": "double",
            "nullable": true
          },
          "departmentId": {
            "type": "integer",
            "description": "Id of the related department. This field is set only if the AssignmentType of the metric is \"Department\", \"Position\" or \"Section\"",
            "format": "int64",
            "nullable": true
          },
          "positionId": {
            "type": "integer",
            "description": "Id of the related position. This field is set only if the AssignmentType of the metric is \"Position\"",
            "format": "int64",
            "nullable": true
          },
          "sectionId": {
            "type": "integer",
            "description": "Id of the related section. This field is set only if the AssignmentType of the metric is \"Section\"",
            "format": "int64",
            "nullable": true
          },
          "timeStamp": {
            "allOf": [
              {
                "$ref": "#/components/schemas/LocalDateTime"
              }
            ],
            "description": "Date and time of the occurrence of the value, in yyyy-MM-ddTHH:mm format.\nIf the metric's TimeUnit is \"Daily\", then this value will always be midnight.\nIf the metric's TimeUnit is \"Hourly\", then this value will always be full hour."
          }
        },
        "additionalProperties": false
      },
      "DataSetValueOutputIEnumerableOpenApiResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DataSetValueOutput"
            },
            "description": "The response data.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Standard response wrapper for OpenAPI endpoints."
      },
      "Era": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "readOnly": true
          }
        },
        "additionalProperties": false
      },
      "FormulaOutput": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Id of the formula",
            "format": "int64"
          },
          "name": {
            "type": "string",
            "description": "Name of the formula"
          },
          "tag": {
            "type": "string",
            "description": "String identifier of the formula, used in formulas"
          },
          "unit": {
            "enum": [
              "Monetary",
              "HoursOfWork",
              "NumberOfPeople",
              "Percentage",
              "Other"
            ],
            "type": "string",
            "description": "Unit of data the metric will evaluate"
          },
          "assignmentType": {
            "enum": [
              "Global",
              "Department",
              "Position",
              "Section"
            ],
            "type": "string",
            "description": "Setting that defines relation between data returned by the metric, and other entities in Planday (departments, positions)"
          },
          "formula": {
            "type": "string",
            "description": "Formula used to evaluate data for this metric"
          }
        },
        "additionalProperties": false
      },
      "FormulaOutputIEnumerableOpenApiResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FormulaOutput"
            },
            "description": "The response data.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Standard response wrapper for OpenAPI endpoints."
      },
      "FormulaValueOutput": {
        "type": "object",
        "properties": {
          "value": {
            "type": "number",
            "description": "Numeric value itself",
            "format": "double",
            "nullable": true
          },
          "departmentId": {
            "type": "integer",
            "description": "Id of the related department.",
            "format": "int64",
            "nullable": true
          },
          "positionId": {
            "type": "integer",
            "description": "Id of the related position. This field is set only if the AssignmentType of one of the formula components is \"Position\"",
            "format": "int64",
            "nullable": true
          },
          "sectionId": {
            "type": "integer",
            "description": "Id of the related section. This field is set only if the AssignmentType of one of the formula components is \"Section\"",
            "format": "int64",
            "nullable": true
          }
        },
        "additionalProperties": false
      },
      "FormulaWithValuesOutput": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "description": "Id of the formula",
            "format": "int64"
          },
          "name": {
            "type": "string",
            "description": "Name of the formula"
          },
          "tag": {
            "type": "string",
            "description": "String identifier of the formula, used in formulas"
          },
          "unit": {
            "enum": [
              "Monetary",
              "HoursOfWork",
              "NumberOfPeople",
              "Percentage",
              "Other"
            ],
            "type": "string",
            "description": "Unit of data the metric will evaluate"
          },
          "assignmentType": {
            "enum": [
              "Global",
              "Department",
              "Position",
              "Section"
            ],
            "type": "string",
            "description": "Setting that defines relation between data returned by the metric, and other entities in Planday (departments, positions)"
          },
          "formula": {
            "type": "string",
            "description": "Formula used to evaluate data for this metric"
          },
          "values": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FormulaValueOutput"
            },
            "description": "List of evaluated values of the metric"
          }
        },
        "additionalProperties": false
      },
      "FormulaWithValuesOutputOpenApiResponse": {
        "type": "object",
        "properties": {
          "data": {
            "allOf": [
              {
                "$ref": "#/components/schemas/FormulaWithValuesOutput"
              }
            ],
            "description": "The response data.",
            "nullable": true
          }
        },
        "additionalProperties": false,
        "description": "Standard response wrapper for OpenAPI endpoints."
      },
      "LocalDate": {
        "type": "object",
        "properties": {
          "calendar": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CalendarSystem"
              }
            ],
            "readOnly": true
          },
          "year": {
            "type": "integer",
            "format": "int32"
          },
          "month": {
            "type": "integer",
            "format": "int32"
          },
          "day": {
            "type": "integer",
            "format": "int32"
          },
          "dayOfWeek": {
            "enum": [
              "None",
              "Monday",
              "Tuesday",
              "Wednesday",
              "Thursday",
              "Friday",
              "Saturday",
              "Sunday"
            ],
            "type": "string",
            "readOnly": true
          },
          "yearOfEra": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "era": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Era"
              }
            ],
            "readOnly": true
          },
          "dayOfYear": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          }
        },
        "additionalProperties": false
      },
      "LocalDateTime": {
        "type": "object",
        "properties": {
          "calendar": {
            "allOf": [
              {
                "$ref": "#/components/schemas/CalendarSystem"
              }
            ],
            "readOnly": true
          },
          "year": {
            "type": "integer",
            "format": "int32"
          },
          "yearOfEra": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "era": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Era"
              }
            ],
            "readOnly": true
          },
          "month": {
            "type": "integer",
            "format": "int32"
          },
          "dayOfYear": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "day": {
            "type": "integer",
            "format": "int32"
          },
          "dayOfWeek": {
            "enum": [
              "None",
              "Monday",
              "Tuesday",
              "Wednesday",
              "Thursday",
              "Friday",
              "Saturday",
              "Sunday"
            ],
            "type": "string",
            "readOnly": true
          },
          "hour": {
            "type": "integer",
            "format": "int32"
          },
          "clockHourOfHalfDay": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "minute": {
            "type": "integer",
            "format": "int32"
          },
          "second": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "millisecond": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "tickOfSecond": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "tickOfDay": {
            "type": "integer",
            "format": "int64",
            "readOnly": true
          },
          "nanosecondOfSecond": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "nanosecondOfDay": {
            "type": "integer",
            "format": "int64",
            "readOnly": true
          },
          "timeOfDay": {
            "allOf": [
              {
                "$ref": "#/components/schemas/LocalTime"
              }
            ],
            "readOnly": true
          },
          "date": {
            "allOf": [
              {
                "$ref": "#/components/schemas/LocalDate"
              }
            ],
            "readOnly": true
          }
        },
        "additionalProperties": false
      },
      "LocalTime": {
        "type": "object",
        "properties": {
          "hour": {
            "type": "integer",
            "format": "int32"
          },
          "clockHourOfHalfDay": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "minute": {
            "type": "integer",
            "format": "int32"
          },
          "second": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "millisecond": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "tickOfSecond": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "tickOfDay": {
            "type": "integer",
            "format": "int64",
            "readOnly": true
          },
          "nanosecondOfSecond": {
            "type": "integer",
            "format": "int32",
            "readOnly": true
          },
          "nanosecondOfDay": {
            "type": "integer",
            "format": "int64",
            "readOnly": true
          }
        },
        "additionalProperties": false
      }
    },
    "securitySchemes": {
      "Bearer": {
        "type": "http",
        "description": "Authorization header using the Bearer token scheme. Example: \"Authorization: Bearer {access_token}\"",
        "scheme": "Bearer"
      }
    }
  },
  "security": [
    {
      "Bearer": [ ]
    }
  ]
}