Aggregate entities over time
POST/v1/entities/aggregate-over-time
This route allows you to perform an aggregation function on a blueprint's entities over a given time range.
To learn more about entities, check out the entity documentation.
For more details about Port's search mechanism, rules, and operators - see the search & query documentation.
Request
Request body schema (JSON)
{
"title": "Body",
"body": {
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"blueprint",
"timeRange",
"timeInterval",
"query",
"measureTimeBy",
"aggregationType"
],
"oneOf": [
{
"title": "Aggregate property",
"properties": {
"blueprint": {
"type": "string",
"description": "The blueprint whose entities you wish to aggregate."
},
"timeRange": {
"type": "object",
"properties": {
"preset": {
"type": "string",
"enum": [
"today",
"yesterday",
"lastDay",
"lastWeek",
"last2Weeks",
"lastMonth",
"last3Months",
"last6Months",
"last12Months",
"last2Years",
"last3Years",
"specific"
]
},
"timeZone": {
"type": "string"
}
},
"required": [
"preset"
],
"additionalProperties": false
},
"timeInterval": {
"type": "string",
"enum": [
"hour",
"day",
"isoWeek",
"month",
"quarter"
]
},
"query": {
"title": "Entities query",
"type": "object",
"properties": {
"combinator": {
"enum": [
"and",
"or"
],
"description": "The combinator to use for the rules."
},
"rules": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"title": "Date Rule",
"properties": {
"property": {
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
},
"operator": {
"enum": [
"between",
"notBetween",
"="
]
},
"value": {
"type": "object",
"oneOf": [
{
"type": "object",
"title": "Date Range",
"properties": {
"from": {
"type": "string",
"format": "date-time"
},
"to": {
"type": "string",
"format": "date-time"
}
},
"required": [
"from",
"to"
]
},
{
"type": "object",
"title": "Date Preset",
"properties": {
"preset": {
"type": "string",
"enum": [
"today",
"tomorrow",
"yesterday",
"lastDay",
"lastWeek",
"last2Weeks",
"lastMonth",
"last3Months",
"last6Months",
"last12Months",
"last2Years",
"last3Years",
"nextDay",
"nextWeek",
"next2Weeks",
"nextMonth",
"next3Months",
"next6Months",
"next12Months"
]
}
},
"required": [
"preset"
]
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
},
"required": [
"property",
"operator",
"value"
],
"additionalProperties": false
},
{
"type": "object",
"title": "Empty Rule",
"oneOf": [
{
"type": "object",
"title": "Empty Rule",
"properties": {
"operator": {
"enum": [
"isEmpty",
"isNotEmpty"
]
},
"property": {
"type": "string"
}
},
"required": [
"operator",
"property"
],
"additionalProperties": false
}
]
},
{
"type": "object",
"title": "Number Rule",
"properties": {
"property": {
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
},
"operator": {
"enum": [
">",
">=",
"<",
"<="
]
},
"value": {
"anyOf": [
{
"type": "number",
"title": "number"
},
{
"type": "string",
"format": "date-time",
"title": "date-time"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
},
"required": [
"property",
"operator",
"value"
],
"additionalProperties": false
},
{
"type": "object",
"title": "Expired Rule",
"oneOf": [
{
"type": "object",
"title": "Expired Rule",
"properties": {
"operator": {
"enum": [
"isExpired",
"isNotExpired"
]
},
"property": {
"type": "string"
}
},
"required": [
"operator",
"property"
],
"additionalProperties": false
}
]
},
{
"type": "object",
"title": "String Rule",
"oneOf": [
{
"type": "object",
"title": "String Rule",
"properties": {
"property": {
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
},
"operator": {
"enum": [
"=",
"!=",
"containsAny",
"contains",
"doesNotContains",
"beginsWith",
"doesNotBeginsWith",
"endsWith",
"doesNotEndsWith",
"in",
"notIn"
]
},
"value": {
"anyOf": [
{
"type": "null",
"title": "null"
},
{
"type": "string",
"title": "string"
},
{
"type": "number",
"title": "number"
},
{
"type": "boolean",
"title": "boolean"
},
{
"type": "string",
"format": "date-time",
"title": "date-time"
},
{
"type": "array",
"items": {
"type": "string"
},
"title": "array"
},
{
"type": "array",
"items": {
"type": "number"
},
"title": "array"
},
{
"type": "array",
"items": {
"type": "boolean"
},
"title": "array"
},
{
"type": "array",
"items": {
"type": "string",
"format": "date-time"
},
"title": "array"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
},
"additionalProperties": false,
"required": [
"property",
"operator",
"value"
]
}
]
},
{
"type": "object",
"title": "Relation Rule",
"properties": {
"operator": {
"enum": [
"relatedTo"
]
},
"blueprint": {
"type": "string"
},
"value": {
"anyOf": [
{
"type": "string",
"title": "string"
},
{
"type": "array",
"items": {
"type": "string"
},
"title": "array"
}
]
},
"direction": {
"enum": [
"upstream",
"downstream"
]
},
"required": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": [
"operator",
"value",
"blueprint"
]
},
{
"type": "object",
"title": "Property schema rule",
"properties": {
"propertySchema": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"format": {
"type": "string"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"format": {
"type": "string"
}
},
"required": [
"type"
]
}
},
"required": [
"type"
],
"additionalProperties": false
},
"operator": {
"enum": [
"=",
"!=",
"contains"
]
},
"value": {
"anyOf": [
{
"type": "null",
"title": "null"
},
{
"type": "string",
"title": "string"
},
{
"type": "number",
"title": "number"
},
{
"type": "boolean",
"title": "boolean"
}
]
}
},
"required": [
"operator",
"propertySchema"
],
"additionalProperties": false
},
{
"type": "object",
"title": "matchAny Rule",
"anyOf": [
{
"type": "object",
"title": "Property matchAny rule",
"properties": {
"property": {
"oneOf": [
{
"type": "object",
"title": "Path filter property",
"properties": {
"path": {
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"type": "string",
"title": "Relation identifier"
},
{
"type": "object",
"title": "Relation with max hops",
"properties": {
"relation": {
"type": "string"
},
"maxHops": {
"type": "number",
"minimum": 1,
"maximum": 15
}
}
}
]
}
},
"fromBlueprint": {
"type": "string"
}
},
"required": [
"path"
],
"additionalProperties": false
},
{
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
]
},
"operator": {
"type": "string",
"enum": [
"matchAny"
]
},
"value": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
]
}
},
"required": [
"property",
"operator",
"value"
],
"additionalProperties": false
}
]
},
{
"allOf": [
"circular(Entities query)",
{
"title": "Nested query"
}
]
}
]
}
}
},
"required": [
"combinator",
"rules"
],
"additionalProperties": false,
"example": {
"combinator": "and",
"rules": [
{
"property": "$blueprint",
"operator": "=",
"value": "service"
},
{
"combinator": "or",
"rules": [
{
"property": "environment",
"operator": "=",
"value": "production"
},
{
"property": "environment",
"operator": "=",
"value": "staging"
}
]
}
]
}
},
"measureTimeBy": {
"type": "string",
"description": "A property of type `datetime` by which the aggregation will be calculated."
},
"specificTimeRange": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"description": "A specific time range [min,max] to aggregate over. If not provided, the time range will be used."
},
"aggregationType": {
"enum": [
"aggregatePropertiesValues"
]
},
"func": {
"type": "string",
"enum": [
"average",
"sum",
"min",
"max",
"median",
"last"
]
},
"properties": {
"type": "array",
"items": {
"type": "string"
},
"description": "A list of properties of type `number` on which the aggregation will be calculated."
}
},
"required": [
"func",
"properties"
],
"additionalProperties": false,
"allOf": [
{
"if": {
"type": "object",
"properties": {
"timeRange": {
"type": "object",
"properties": {
"preset": {
"enum": [
"last2Years",
"last3Years"
]
}
}
}
}
},
"then": {
"type": "object",
"properties": {
"timeInterval": {
"enum": [
"quarter"
]
}
}
}
},
{
"if": {
"type": "object",
"properties": {
"timeRange": {
"type": "object",
"properties": {
"preset": {
"enum": [
"specific"
]
}
}
}
},
"required": [
"timeRange"
]
},
"then": {
"type": "object",
"properties": {
"specificTimeRange": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"description": "A specific time range [min,max] to aggregate over. If not provided, the time range will be used."
}
},
"required": [
"specificTimeRange"
]
}
}
]
},
{
"title": "Count entities",
"properties": {
"blueprint": {
"type": "string",
"description": "The blueprint whose entities you wish to aggregate."
},
"timeRange": {
"type": "object",
"properties": {
"preset": {
"type": "string",
"enum": [
"today",
"yesterday",
"lastDay",
"lastWeek",
"last2Weeks",
"lastMonth",
"last3Months",
"last6Months",
"last12Months",
"last2Years",
"last3Years",
"specific"
]
},
"timeZone": {
"type": "string"
}
},
"required": [
"preset"
],
"additionalProperties": false
},
"timeInterval": {
"type": "string",
"enum": [
"hour",
"day",
"isoWeek",
"month",
"quarter"
]
},
"query": {
"title": "Entities query",
"type": "object",
"properties": {
"combinator": {
"enum": [
"and",
"or"
],
"description": "The combinator to use for the rules."
},
"rules": {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"title": "Date Rule",
"properties": {
"property": {
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
},
"operator": {
"enum": [
"between",
"notBetween",
"="
]
},
"value": {
"type": "object",
"oneOf": [
{
"type": "object",
"title": "Date Range",
"properties": {
"from": {
"type": "string",
"format": "date-time"
},
"to": {
"type": "string",
"format": "date-time"
}
},
"required": [
"from",
"to"
]
},
{
"type": "object",
"title": "Date Preset",
"properties": {
"preset": {
"type": "string",
"enum": [
"today",
"tomorrow",
"yesterday",
"lastDay",
"lastWeek",
"last2Weeks",
"lastMonth",
"last3Months",
"last6Months",
"last12Months",
"last2Years",
"last3Years",
"nextDay",
"nextWeek",
"next2Weeks",
"nextMonth",
"next3Months",
"next6Months",
"next12Months"
]
}
},
"required": [
"preset"
]
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
},
"required": [
"property",
"operator",
"value"
],
"additionalProperties": false
},
{
"type": "object",
"title": "Empty Rule",
"oneOf": [
{
"type": "object",
"title": "Empty Rule",
"properties": {
"operator": {
"enum": [
"isEmpty",
"isNotEmpty"
]
},
"property": {
"type": "string"
}
},
"required": [
"operator",
"property"
],
"additionalProperties": false
}
]
},
{
"type": "object",
"title": "Number Rule",
"properties": {
"property": {
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
},
"operator": {
"enum": [
">",
">=",
"<",
"<="
]
},
"value": {
"anyOf": [
{
"type": "number",
"title": "number"
},
{
"type": "string",
"format": "date-time",
"title": "date-time"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
},
"required": [
"property",
"operator",
"value"
],
"additionalProperties": false
},
{
"type": "object",
"title": "Expired Rule",
"oneOf": [
{
"type": "object",
"title": "Expired Rule",
"properties": {
"operator": {
"enum": [
"isExpired",
"isNotExpired"
]
},
"property": {
"type": "string"
}
},
"required": [
"operator",
"property"
],
"additionalProperties": false
}
]
},
{
"type": "object",
"title": "String Rule",
"oneOf": [
{
"type": "object",
"title": "String Rule",
"properties": {
"property": {
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
},
"operator": {
"enum": [
"=",
"!=",
"containsAny",
"contains",
"doesNotContains",
"beginsWith",
"doesNotBeginsWith",
"endsWith",
"doesNotEndsWith",
"in",
"notIn"
]
},
"value": {
"anyOf": [
{
"type": "null",
"title": "null"
},
{
"type": "string",
"title": "string"
},
{
"type": "number",
"title": "number"
},
{
"type": "boolean",
"title": "boolean"
},
{
"type": "string",
"format": "date-time",
"title": "date-time"
},
{
"type": "array",
"items": {
"type": "string"
},
"title": "array"
},
{
"type": "array",
"items": {
"type": "number"
},
"title": "array"
},
{
"type": "array",
"items": {
"type": "boolean"
},
"title": "array"
},
{
"type": "array",
"items": {
"type": "string",
"format": "date-time"
},
"title": "array"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
},
"additionalProperties": false,
"required": [
"property",
"operator",
"value"
]
}
]
},
{
"type": "object",
"title": "Relation Rule",
"properties": {
"operator": {
"enum": [
"relatedTo"
]
},
"blueprint": {
"type": "string"
},
"value": {
"anyOf": [
{
"type": "string",
"title": "string"
},
{
"type": "array",
"items": {
"type": "string"
},
"title": "array"
}
]
},
"direction": {
"enum": [
"upstream",
"downstream"
]
},
"required": {
"type": "boolean"
}
},
"additionalProperties": false,
"required": [
"operator",
"value",
"blueprint"
]
},
{
"type": "object",
"title": "Property schema rule",
"properties": {
"propertySchema": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"format": {
"type": "string"
},
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"format": {
"type": "string"
}
},
"required": [
"type"
]
}
},
"required": [
"type"
],
"additionalProperties": false
},
"operator": {
"enum": [
"=",
"!=",
"contains"
]
},
"value": {
"anyOf": [
{
"type": "null",
"title": "null"
},
{
"type": "string",
"title": "string"
},
{
"type": "number",
"title": "number"
},
{
"type": "boolean",
"title": "boolean"
}
]
}
},
"required": [
"operator",
"propertySchema"
],
"additionalProperties": false
},
{
"type": "object",
"title": "matchAny Rule",
"anyOf": [
{
"type": "object",
"title": "Property matchAny rule",
"properties": {
"property": {
"oneOf": [
{
"type": "object",
"title": "Path filter property",
"properties": {
"path": {
"type": "array",
"minItems": 1,
"items": {
"anyOf": [
{
"type": "string",
"title": "Relation identifier"
},
{
"type": "object",
"title": "Relation with max hops",
"properties": {
"relation": {
"type": "string"
},
"maxHops": {
"type": "number",
"minimum": 1,
"maximum": 15
}
}
}
]
}
},
"fromBlueprint": {
"type": "string"
}
},
"required": [
"path"
],
"additionalProperties": false
},
{
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
]
},
"operator": {
"type": "string",
"enum": [
"matchAny"
]
},
"value": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"title": "Contexted property",
"oneOf": [
{
"type": "string"
},
{
"type": "object",
"title": "User-context field",
"properties": {
"property": {
"type": "string"
},
"context": {
"type": "string",
"enum": [
"user",
"userTeams"
]
}
},
"required": [
"property",
"context"
]
}
]
}
]
}
},
"required": [
"property",
"operator",
"value"
],
"additionalProperties": false
}
]
},
{
"allOf": [
"circular(Entities query)",
{
"title": "Nested query"
}
]
}
]
}
}
},
"required": [
"combinator",
"rules"
],
"additionalProperties": false,
"example": {
"combinator": "and",
"rules": [
{
"property": "$blueprint",
"operator": "=",
"value": "service"
},
{
"combinator": "or",
"rules": [
{
"property": "environment",
"operator": "=",
"value": "production"
},
{
"property": "environment",
"operator": "=",
"value": "staging"
}
]
}
]
}
},
"measureTimeBy": {
"type": "string",
"description": "A property of type `datetime` by which the aggregation will be calculated."
},
"specificTimeRange": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"description": "A specific time range [min,max] to aggregate over. If not provided, the time range will be used."
},
"aggregationType": {
"enum": [
"countEntities"
]
},
"func": {
"type": "string",
"enum": [
"count",
"average"
]
},
"breakdownProperty": {
"type": "string",
"description": "A blueprint's property by which you want to break down the data."
}
},
"required": [
"func"
],
"additionalProperties": false,
"allOf": [
{
"if": {
"type": "object",
"properties": {
"timeRange": {
"type": "object",
"properties": {
"preset": {
"enum": [
"last2Years",
"last3Years"
]
}
}
}
}
},
"then": {
"type": "object",
"properties": {
"timeInterval": {
"enum": [
"quarter"
]
}
}
}
},
{
"if": {
"type": "object",
"properties": {
"timeRange": {
"type": "object",
"properties": {
"preset": {
"enum": [
"specific"
]
}
}
}
},
"required": [
"timeRange"
]
},
"then": {
"type": "object",
"properties": {
"specificTimeRange": {
"type": "array",
"items": {
"type": "number"
},
"minItems": 2,
"maxItems": 2,
"description": "A specific time range [min,max] to aggregate over. If not provided, the time range will be used."
}
},
"required": [
"specificTimeRange"
]
}
}
]
}
]
}
}
},
"required": true
}
}Responses
- 200
- 401
- 404
- 413
- 422
Retrieved successfully.
Default Response
A resource with the provided identifier was not found
Request body is too large (limit is 1MiB)
The json provided does not match the route's schema
Responses (JSON)
{
"responses": {
"200": {
"description": "Retrieved successfully.",
"content": {
"application/json": {
"schema": {
"description": "Retrieved successfully.",
"type": "object",
"properties": {
"ok": {
"enum": [
true
]
},
"result": {
"type": "object",
"properties": {
"minDate": {
"type": "number"
},
"maxDate": {
"type": "number"
},
"data": {
"type": "array",
"items": {
"object": {
"type": "object",
"properties": {
"date": {
"type": "number"
}
},
"additionalProperties": {
"type": "number"
}
}
}
}
}
}
},
"required": [
"ok"
],
"additionalProperties": false
}
}
}
},
"401": {
"description": "Default Response",
"content": {
"application/json": {
"schema": {
"properties": {
"ok": {
"const": false
},
"error": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"ok",
"error"
],
"additionalProperties": false
}
}
}
},
"404": {
"description": "A resource with the provided identifier was not found",
"content": {
"application/json": {
"schema": {
"properties": {
"ok": {
"const": false
},
"error": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"ok",
"error",
"message"
],
"additionalProperties": false,
"description": "A resource with the provided identifier was not found"
}
}
}
},
"413": {
"description": "Request body is too large (limit is 1MiB)",
"content": {
"application/json": {
"schema": {
"properties": {
"ok": {
"const": false
},
"error": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"ok",
"error"
],
"additionalProperties": false,
"description": "Request body is too large (limit is 1MiB)"
}
}
}
},
"422": {
"description": "The json provided does not match the route's schema",
"content": {
"application/json": {
"schema": {
"properties": {
"ok": {
"const": false
},
"error": {
"type": "string"
},
"message": {
"type": "string"
}
},
"required": [
"ok",
"error",
"message"
],
"additionalProperties": false,
"description": "The json provided does not match the route's schema"
}
}
}
}
}
}