Skip to main content

Events Push API

The main endpoints is depended on the deployed site. For this document, we'll target the Development environment, in which, the main endpoints for event collecting are https://dev.primedata.ai/powehi/context and https://dev.primedata.ai/powehi/smile.

info

There's a subtle difference between these two endpoints. But let's just use the latter for now.

Authentication​

These are the two mandatory headers to authenticate against Tracking API:

  • X-Client-ID
  • X-Client-Access-Token

Check out Register Data Sources to see how to acquire this pair.

Setup​

For an event to be captured on Prime side, the coming events must have its type pre-registered. See Register Event Schemas to make a new event schema.

Sending events​

For example, let's say we created an Event Schema with the name view. Suppose it has an single properties named url. Then you could push an event to Prime by:

$ curl -X POST "https://dev.primedata.ai/powehi/smile"  \
-H "X-Client-Id: ${YOUR_DATA_SOURCE_ID}" \
-H "X-Client-Access-Token: ${YOUR_DATA_SOURCE_WRITE_KEY}" \
-H 'Content-Type: application/json' \
-d '{
"sessionId": "45d01662-45ad-4f52-9d4f-ef77fde0b17a",
"events": [
{
"eventType": "view",
"properties": {
"url": "https://example.com"
},
"scope": ${YOUR_DATA_SOURCE_ID},
"timeStamp": "2021-10-15T18:49:00+07:00",
"source": { "itemId": "_", "itemType": "_", "scope": ${YOUR_DATA_SOURCE_ID} },
"target": { "itemId": "_", "itemType": "_", "scope": ${YOUR_DATA_SOURCE_ID} }
}
]
}' \
-D -

Body attributes​

Top-level attributes​

NameRequiredDescription
sessionIdNoA unique random ID generated on client side. Any format is okay, but preferably a UUID.
eventsYesAn array of Event objects. Max 500 events

events' object attributes​

EventRequiredDescription
eventTypeYesThe name that you setup when creating the Event Schema.
scopeYesShould be exactly the same as the data source ID / X-Client-ID, currently this has to be specified explicitly.
timeStampYesISO-8601 datetime format, logical time when the event occurred.
sendAtNoISO-8601 datetime format, optional client sending time.
propertiesNo*Corresponds to the properties that were setup on Event Schema. Make sure all the required properties are specified with the correct data type. (Redundant properties will be trimmed out on server side).
sourceYesPreserved for the profile context data.
targetYesPreserved for the entity data.

Entity's (source / target) attributes​

EntityRequiredDescription
itemIdYesLeave this as "_" if there's no logical ID for the entity.
itemTypeYesLeave this as "_" if there's no logical type for the entity. (identify event must has this set to analyticsUser)
scopeYesThis is identical to the data source ID / X-Client-ID, currently this has to be specified explicitly.
propertiesNoDepends on the event's schema. For built-in events, currently only identify event will have this specified (with the respected profile's properties).

Response​

The described request should response with a 200-status response with a body of:

{
"processedEvents": 2,
"profileId": null
}

2 here means there are 2 events is processed. null here means there's no profile get updated from this event.

Error body​

401 Unauthorized
{
"error": {
"message": "client: unauthorized"
}
}
422 Unprocessable Entity
{
"error": {
"details": [
{
"field": "source.itemId",
"description": "String length must be greater than or equal to 1"
}
],
"message": "Schema is invalid"
}
}

API Response​

CODESTATUSDESCRIPTIONMESSAGE
200OKEverything worked as expected.
400Bad Request
401UnauthorizedNo valid Access Token provided.client: unauthorized
404Not FoundThe requested resource doesn’t exist.
422Unprocessable EntityThere are something wrong with your event's field value.scope is not exists, Item not found, Schema is invalid
429Too Many RequestsMore than 1024 concurrent request from this ip
5xxServer ErrorsSomething went wrong on PrimeData’s side.

That newly ingested event can be inspected at "Event Logs" of your Data Source on https://dev.primedata.ai/Prime/en/data-source.