A Calculated Attribute is a read-only value about a single user, providing granular insight into user behavior. These attributes are defined in mParticle and are computed automatically over time by using the raw data stream of events and user information.
The calculated attributes resource group is only accessible at https://api.mparticle.com/platform/v2
, and does not require the ?accountId
query string parameter.
GET
/workspaces/1234/calculatedattributes?name=ca1
curl \
-X GET \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes?name=ca1"
Name | Type | Description |
---|---|---|
name | string |
Optional parameter to filter by name. |
[
{
"id": 5,
"name": "ca1",
"description": "Calculated attribute description.",
"created_by": "user@mparticle.com",
"created_on": "2019-09-10T15:34:44.69",
"last_modified_on": "2019-12-06T15:04:22.043",
"last_modified_by": "user@mparticle.com",
"active_definition": {
"recipe_type": "event",
"datapoint": {
"type": "event",
"event_name": "Purchase",
"attribute_name": "Total Amount",
"event_type": "commerce_event",
"custom_event_type": "purchase",
"attribute_category": "product_attribute",
"use_product_quantity": true
},
"conditions": [
{
"type": "number",
"operator": "equals",
"attribute_name": "Checkout Step",
"value": "22",
"values": null,
"min_value": null,
"max_value": null
}
],
"calculation_type": "sum",
"time_period": {
"type": "since",
"date": "2019-10-01T00:00:00",
"within": null,
"within_unit": null
},
"seeding": {
"cutoff_date": "2019-10-02T00:00:00"
}
},
"draft_definition": {
"recipe_type": "event",
"datapoint": {
"type": "event",
"event_name": "Purchase",
"attribute_name": "Total Amount",
"event_type": "commerce_event",
"custom_event_type": "purchase",
"attribute_category": "product_attribute",
"use_product_quantity": true
},
"conditions": null,
"calculation_type": "sum",
"time_period": {
"type": "since",
"date": "2019-10-01T00:00:00",
"within": null,
"within_unit": null
},
"seeding": null
},
"audience_count": 1,
"activated_on": "2020-02-18T19:24:50.426Z",
"activated_by": "user@mparticle.com"
}
]
HEAD
/workspaces/1234/calculatedattributes?name=ca1
curl \
-X HEAD \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes?name=ca1"
Name | Type | Description |
---|---|---|
name | string |
Optional parameter to filter by name. |
HTTP Code 204 — Calculated Attribute resource(s) exist.
HTTP Code 404 — Calculated Attribute resource(s) do not exist.
The response body will be empty.
POST
/workspaces/1234/calculatedattributes
curl \
-X POST \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes" \
-d '{
"name": "New Calculated Attribute",
"draft_definition": {
"recipe_type": "event",
"datapoint": {
"type": "event",
"event_name": "Add To Cart",
"attribute_name": null,
"event_type": "commerce_event",
"custom_event_type": "add_to_cart",
"attribute_category": "product_attribute",
"use_product_quantity": true
},
"conditions": [],
"calculation_type": "count",
"time_period": {
"type": "since",
"date": "2020-01-24T00:00:00",
"within": null,
"within_unit": null
},
"seeding": {
"cutoff_date": "2020-01-26T00:00:00"
}
}
}'
Name | Data Type | Required | Description |
---|---|---|---|
name |
string | Required | Calculated attribute name. |
description |
string | Optional | Calculated attribute description. |
draft_definition |
object | Required | Calculated attribute definition. |
draft_definition
Name | Data Type | Required | Description |
---|---|---|---|
recipe_type |
string | Required | Currently only “event” is supported. |
data_point |
object | Required | A unique datapoint in the system. This could be an event, event attribute or user attribute, but currently only events are supported. |
conditions |
object array | Optional | An array of conditions that must be met for the datapoint to qualify for the recipe. |
calculation_type |
string | Required | The calculation type to be performed on the datapoint that will result in the value of the calculated attribute. One of:
|
time_period |
object | Required | The time period to which the calculation should be applied. |
seeding |
object | Optional | Settings for seeding the calculated attribute. |
draft_definition.data_point
Name | Data Type | Required | Description |
---|---|---|---|
type |
string | Required | One of “event”, “event_attribute”, or “user_attribute”. |
event_name |
string | Required | App event name. |
attribute_name |
string | Optional | If targeting an event attribute or user attribute, this property is required. In the case of targeting an event attribute, the corresponding event name must be set in the event_name property. |
event_type |
string | Required | See event_type field in Events API for supported values. |
custom_event_type |
string | Optional | Only applicable to app (custom) events. See custom_event_type field in Events API for supported values. |
attribute_category |
string | Optional | Only applicable when attribute_name is provided. Value can be one of “event_attribute”, “product_attribute”, or “promotion_attribute”. If nothing is set the default value will be set as “event_attribute”. |
use_product_quantity |
bool | Optional | Indicates that the product quantity should be used when calculating Average or Most Frequent calculations with e-commerce event types. Only applies when attribute_category is one of “product_attribute” or “promotion_attribute”. |
draft_definition.conditions
Name | Data Type | Required | Description |
---|---|---|---|
type |
string | Required | The type of data being operated on. One of “string”, “number”, “boolean”, or “date”. |
operator |
string | Required | The operator to apply. The supported list of operators depends on the type of the selected attribute. See type-map table below. |
attribute_name |
string | Required | The name of an attribute that belongs to the event selected in the datapoint section. If the event does not contain the attribute, it is implied that the condition is not met. |
value |
string | Conditionally Required | If the operator requires a single value, then this field will be used and is required. |
values |
string array | Conditionally Required | If the operator requires a set of values, such as ”in_list”, then the set will be provided in this array and is required. |
min_value |
string | Conditionally Required | If the operator requires defining a range, then the min value of the range will be set here. |
max_value |
string | Conditionally Required | If the operator requires defining a range, then the max value of the range will be set here. |
Operator | String | Number | Boolean | Date |
---|---|---|---|---|
exists | Yes | Yes | Yes | Yes |
not_exists | Yes | Yes | Yes | Yes |
empty | Yes | Yes | Yes | Yes |
in_list | Yes | Yes | No | No |
contains | Yes | No | No | No |
not_contains | Yes | No | No | No |
pattern | Yes | No | No | No |
equals | Yes | Yes | Yes | Yes |
not_equals | Yes | Yes | No | No |
greater_than | No | Yes | No | No |
greater_or_equal | No | Yes | No | No |
less_than | No | Yes | No | No |
less_than_or_equal | No | Yes | No | No |
before | No | No | No | Yes |
after | No | No | No | Yes |
between | No | Yes | No | No |
between_dates | No | No | No | Yes |
draft_definition.time_period
Name | Data Type | Required | Description |
---|---|---|---|
type |
string | Required | “since” or “within” |
date |
string | Conditionally Required | A date string in ISO 8601 format. Optional for type “all”. |
within_unit |
string | Conditionally Required | Required if type is within . Value is one of “days” or “weeks”. |
within |
integer | Conditionally Required | Required if type is within . Value corresponds to the unit chosen in within_unit . |
draft_definition.seeding
Name | Data Type | Required | Description |
---|---|---|---|
cutoff_date |
string | Required | A date string in ISO 8601 format. mParticle will only use data after this date to compute the calculated attribute. Client is responsible for calculating the value based on data prior to this date and send mParticle a seed value. |
The response will be an integer identifier for the new Calculated Attribute.
Message |
Description |
---|---|
Field ‘name’ is required. | The calculate attribute’s name is missing. |
Field ‘name’ must be unique. | A calculated attribute with that name already exists in the workspace. |
Field ‘draft_definition’ is required. | The calculated attribute is missing the draft_definition field. |
Field ‘time_period.type’ = ‘all’ is not supported. | The time period type all is not supported. |
‘time_period.date’ must be on or after the earliest date available of {date} | The date isn’t available according to the audience retention period of your subscription plan. |
The within time period cannot exceed your configured retention period of {N} days for Calculated Attributes | The date specified for the within calculation date range exceeds the audience retention period of your subscription plan. |
Invalid recipe type | Only type event is currently supported. |
Invalid calculation type | The draft_definition.calculation_type field is missing or invalid. See schema definition for enum values. |
Invalid time period specification | The draft_definition.time_period field is missing or invalid. |
Invalid ‘type’ time period specification | The draft_definition.time_period.type field is missing or invalid. See schema definition for enum values. |
Invalid ‘within’ time period specification | The draft_definition.time_period.within field is missing or invalid. Must be a positive integer. |
Invalid ‘within_unit’ time period specification | The draft_definition.time_period.within_unit field is missing or invalid. See schema definition for enum values. |
Invalid data point custom event name | The draft_definition.datapoint.event_name field is required when draft_definition.datapoint.event_type is custom_event . |
Invalid data point custom event type | The draft_definition.datapoint.custom_event_type field is only allowed when draft_definition.datapoint.event_type is custom_event or commerce_event . |
Invalid condition definition | One of the conditions in draft_definition.conditions is invalid. |
Invalid condition definition type | A condition’s type field is invalid. See schema definition for enum values. |
Invalid string condition operator | A string condition’s operator field is invalid. See schema definition for enum values. |
Condition attribute name must be specified | A condition’s attribute_name field is invalid or missing. |
In-list condition values must be specified | A condition’s values field is invalid or missing. Field value is ignored when using the in_list operator. |
String condition value must be specified | A string condition’s value field is invalid or missing. |
Invalid numeric condition operator | A numeric condition’s operator field is invalid. See schema definition for enum values. |
Invalid numeric in-list condition values | A numeric condition’s values field is invalid or missing. Field value is ignored when using the in_list operator. |
Invalid numeric condition minimum value | A numeric condition’s value field is invalid or missing. Field min_value is required when using a range operator. |
Invalid numeric condition maximum value | A numeric condition’s value field is invalid or missing. Field max_value is required when using a range operator. |
Invalid numeric condition value | A numeric condition’s value field is invalid or missing. |
Invalid boolean condition operator | A boolean condition’s operator field is invalid. See schema definition for enum values. |
Invalid boolean condition value | A boolean condition’s value field is invalid or missing. |
Invalid date condition operator | A date condition’s operator field is invalid. See schema definition for enum values. |
Invalid datetime in-list condition values | A date condition’s values field is invalid or missing. Field value is ignored when using the in_list operator. |
Invalid date condition minimum value | A date condition’s value field is invalid or missing. Field min_value is required when using a range operator. |
Invalid date condition maximum value | A date condition’s value field is invalid or missing. Field max_value is required when using a range operator. |
Invalid date condition value | A date condition’s value field is invalid or missing. |
Condition value must be empty | A range condition has a value in the value field. |
Condition values must be empty | A condition that does not target a list has a value in the values field |
Condition minimum value must be empty | A non-range condition has a value in the min_value field. |
Condition maximum value must be empty | A non-range condition has a value in the max_value field. |
GET
/workspaces/1234/calculatedattributes/5678
curl \
-X GET \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678"
{
"id": 0,
"name": "string",
"description": "string",
"created_by": "string",
"created_on": "2020-01-30T17:37:41.608Z",
"last_modified_on": "2020-01-30T17:37:41.608Z",
"last_modified_by": "string",
"active_definition": {
"recipe_type": "event",
"data_point": {
"type": "event",
"event_name": "string",
"attribute_name": "string",
"event_type": "unknown",
"custom_event_type": "unknown"
}
"conditions": [
{
"type": "string",
"operator": "exists",
"attribute_name": "string",
"value": "string",
"values": [
"string"
],
"min_value": "string",
"max_value": "string"
}
],
"calculation_type": "count",
"time_period": {
"type": "all",
"date": "2020-01-30",
"within": 0,
"within_unit": "days"
}
},
"draft_definition": {
"recipe_type": "event",
"data_point": {
"type": "event",
"event_name": "string",
"attribute_name": "string",
"event_type": "unknown",
"custom_event_type": "unknown"
}
"conditions": [
{
"type": "string",
"operator": "exists",
"attribute_name": "string",
"value": "string",
"values": [
"string"
],
"min_value": "string",
"max_value": "string"
}
],
"calculation_type": "count",
"time_period": {
"type": "all",
"date": "2020-01-30",
"within": 0,
"within_unit": "days"
}
},
"audience_count": 0,
"activated_on": "2020-02-18T19:24:50.426Z",
"activated_by": "user@mparticle.com"
}
DELETE
/workspaces/1234/calculatedattributes/5678
curl \
-X DELETE \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678"
HTTP Code 204 — Calculated Attribute was successfully deleted.
HTTP Code 404 — Calculated Attribute does not exist.
The response body will be empty.
Use this endpoint to create or update a draft of your Calculated Attribute definition. When a Calculated Attribute is updated, the draft_definition
is changed. Once the Calculated Attribute is activated, the draft_definition
is moved into the active_definition
and the new definition is used to calculate values. The active_definition
property cannot be updated directly.
You can only rename a Calculated Attribute before it has been activated; Once activated, the name
is read-only. The only property you will be allowed to update in this state is the description
.
PUT
/workspaces/1234/calculatedattributes/5678
curl \
-X PUT \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678" \
-d '{
"name": "New Name",
"draft_definition": {
"recipe_type": "event",
"datapoint": {
"type": "event",
"event_name": "Add To Cart",
"attribute_name": null,
"event_type": "commerce_event",
"custom_event_type": "add_to_cart"
},
"conditions": [],
"calculation_type": "count",
"time_period": {
"type": "since",
"date": "2020-01-24T00:00:00",
"within": null,
"within_unit": null
}
}
}'
HTTP Code 204 — Calculated Attribute was successfully updated. HTTP Code 404 — Calculated Attribute does not exist.
In addition to the validation errors from Create a Calculated Attribute.
Message | Description |
---|---|
Calculated attribute name cannot be changed once the calculated attribute has been activated. | You can only update the name of a calculated attribute that has not been acitvated. |
Use this endpoint to activate a calculated attribute. You must activate the Calculated Attribute before it can be used elsewhere in the system. A calculated attribute can only be activated if you have not exceeded the maximum limit of active calculated attributes for your account.
POST
/workspaces/1234/calculatedattributes/5678/activation
The request body is empty for this POST
.
curl \
-X POST \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678/activation"
HTTP Code 204 — Calculated Attribute was successfully activated.
Message | Description |
---|---|
You have reached the account limit on active calculated attributes. | To increase limit, contact your account representative or delete unneeded active calculated attributes. |
No draft definition was found to activate. | You are attempting to activate a calculated attribute that has a invalid definition. |
A calculated attribute’s activation status tells you whether the calculated attribute has been activated and when and who activated it.
GET
/workspaces/1234/calculatedattributes/5678/activation
curl \
-X GET \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678/activation"
{
"calculated_attribute_id": 5678,
"is_active": true,
"activated_on": "2020-02-18T19:24:50.426Z",
"activated_by": "user@mparticle.com"
}
Use this endpoint to discard a calculated attribute’s draft definition.
DELETE
/workspaces/1234/calculatedattributes/5678/draft
curl \
-X DELETE \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678/draft"
HTTP Code 204 — Calculated Attribute’s draft definition was successfully deleted.
HTTP Code 404 — Calculated Attribute does not exist.
The response body will be empty.
A calculated attribute’s calculation status gives you the calculation progress and an estimated completion date.
GET
/workspaces/1234/calculatedattributes/5678/calculation
curl \
-X GET \
-H "Authorization: Bearer YWIxMjdi341GHhnDnjsdKAJQxNjdjYuOJABbg6HdI.8V6HhxW-" \
"https://api.mparticle.com/platform/v2/workspaces/1234/calculatedattributes/5678/calculation"
{
"id": 5678,
"name": "New Name",
"revision_id": 123,
"is_calculated": false,
"calculation_percent_complete": 50,
"estimated_completion_time": "2020-01-29T19:24:19.051Z"
}
Was this page helpful?