Retrieve Insights Using the REST API

If you want to retrieve your insights programmatically you can use our /insights REST API endpoint and get a JSON of requested insights.

In order to access Mona's API, first an accessToken must be generated and added to the request.
Once you have your accessToken you can add it to your authorization and send the following request:

curl --location --request POST 'https://api{YOUR-USER-ID}.monalabs.io/insights' \
--header 'Authorization: Bearer YOUR-ACCESS-TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "arcClass": "YOUR-ARC-CLASS",
    "minSegmentSize": 200,
    "timeRangeSeconds": [
        1619611990,
        1619784790
    ],
    "insight_types": [
        "KapiAverageDriftInSegment",
        "KapiSumDriftInSegment"
    ],
    "metric_name": [
        "credit_score",
        "offered_approved_ammount"
    ],
    "min_insight_score": 3.5,
    "first_discovered_on_range_seconds": [
        1619687590,
        1619699673
    ]
}'
import requests
url = "https://api{YOUR-USER-ID}.monalabs.io/insights"

payload={
  "arcClass": "YOUR-ARC-CLASS",
  "minSegmentSize": {Some Integer},
  "timeRangeSeconds": [
    "startTimestamp",
    "endTimestamp"
  ]
}

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

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

print(response.text)
from mona_sdk.client import Client

api_key = <YOUR-API-KEY>
secret = <YOUR-SECRET>

my_mona_client = Client(api_key, secret)

my_mona_client.get_insights(
    context_class="YOUR-CONTEXT-CLASS",
    min_segment_size=10,
    time_range_seconds=[1644416612, 1644466612],
)

Optional args:

  • "insight_types" - A filter to get only insights of these types.
  • "metric_name" - A filter to get only insights which include these metrics.
  • "min_insight_score" - A filter to get only insights which have a score higher then stated here.
  • "first_discovered_on_range_seconds" - a range (startTimestamp and endTimestamp) in which insights were discovered for the first time.

Did this page help you?