Export data directly via REST endpoint

Background

In addition to the Mona python SDK, users can leverage a REST endpoint to export their data to Mona. If you are a new user, you will find all the export options on the “Getting Started” page in your dashboard. Under "REST API" will be the userId and the user's designated URL, required to access the API.

Aside from the userId and URL, to access Mona's API, first an YOUR-ACCESS-TOKEN must be generated and added to the request. Click here to learn how to generate YOUR-ACCESS-TOKEN.

📘

YOUR-USER-ID

your user-id can be found in the first line of the configuration file, which can be downloaded via the configurations page

curl --location --request POST 'https://incoming{YOUR-USER-ID}.monalabs.io/export' \
--header 'Authorization: Bearer YOUR-ACCESS-TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "userId": "YOUR-USER-ID",
    "messages": [
        	{
            	"arcClass": "YOUR-ARC-CLASS",
            	"contextId":"CONTEXT",
            	"action": "NEW",
            	"exportTimestamp":TIMESTAMP,
            	"message":{YOUR-JSON}
          	}
    ]
}'
import requests
import time

url = "https://incoming{YOUR-USER-ID}.monalabs.io/export"

timeStamp = time.time()

payload={
    "userId": "{YOUR-USER-ID}",
    "messages": [
        {
            "arcClass": "YOUR-ARC-CLASS",
            "contextId": "CONTEXT",
            "exportTimestamp": timeStamp,
            "message": {YOUR-JSON}
        }
    ]
}

headers = {
  'Authorization': 'Bearer YOUR-ACCESS-TOKEN',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, json=payload)

print(response.text)

Definition

POST /export

Application JSON payload

  • (required) userId - as provided to you by us.
  • (required) messages - a json array with message object, each with:
    • (required) arcClass - string - As agreed with us to classify the messages.
    • (required) message - json object - a single json of the exported scores/values.
    • (optional) contextId - string - the key used to store the data on our end.
    • (optional) action - string - the processing action to be done with the following context i
    • (optional) exportTimestamp - int - timestamp (in seconds since epoch) to overwrite
      exported time (e.g. backfill past calls default is current time)

Example

In this example, we assume that the Mona-supplied userId is 1234567890, and that the config expects an arc class - "arcClassName",

Below is a JSON example of how it would look like when sending a number of messages as 1 JSON - two of the messages have a contextId of "ID_123" which Mona will merge together, and one with a different contextId of "ID_124".

{
  "userId": 1234567890,
  "messages": [
    {
      "arcClass": "arcClassName",
      "contextId": "ID_123",
      "action": "NEW",
      "exportTimestamp": 1620086509,
      "message": {
        "company-id": "79sg7723-0253438g3453",
        "browser": "chrome",
        "text_length": 50,
        "top_tagged_brand": "adidas"
      }
    },
    {
      "arcClass": "arcClassName",
      "action": "ADD",
      "contextId": "ID_123",
      "exportTimestamp": 1620086509,
      "message": {
        "coutry": "usa"
      }
    },
    {
      "arcClass": "arcClassName",
      "contextId": "ID_124",
      "action": "NEW",
      "exportTimestamp": 1620086509,
      "message": {
        "company-id": "2435f32-02ve3538g5232",
        "browser": "safari",
        "text_length": 30,
        "top_tagged_brand": "nike"
      }
    }
  ]
}