Skip to content

Fetching Goal Metrics

Overview

Giosg platform provides APIs for fetching metrics from the Goals (previously) active. This tutorial guides you through requesting the goals within the organization, for use in your own application.

Prerequisites

A guide on how to create an API token can be found here

Once you have obtained your API token(s), define the Authorization HTTP header for all your API requests:

1
Authorization: Token <api_key>

You should replace the <api_key> with your API token

Remember that the api token is connected to the user that created the token, which means that if the user is deleted the api token will also be invalidated. You can create an extra user and create the token with this user, remember to name the user so that it doesn’t get deleted by mistake e.g “Reporting api-user do not delete”

Gather your goal ids

Once you start fetching your goal metrics you will need to gather your goal ids. This you can do through the Goals API. Then we need to get the appropriate metrics from the new API.

Getting your metrics

POST https://api.giosg.com/api/reporting/workflow/v1/orgs/<organization_id>/query/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests

GIOSG_SERVICE_BASE_URL = "https://api.giosg.com"
token = "<giosg account token>"
organization_id = "<uuid>"

json = {
    "select": [
        "label"
    ],
    "count": [
        "value"
    ],
    "sum": [
        "value"
    ],
    "group_by": [
        "label",
        "value"
    ],
    "where": [
        {
            "field": "category",
            "search": "goal"
        }
    ],
    "timespan": {
        "start": "2023-06-25T00:00:00.000Z",
        "end": "2023-06-26T23:59:59.999Z"
    }
}


def fetch_goal_metrics():
    response = requests.post(
        "{}/api/reporting/workflow/v1/orgs/{}/query".format(GIOSG_SERVICE_BASE_URL, organization_id),
        headers={'Authorization': 'Token ' + token},
        json=json)
    response.raise_for_status()
    return response.json()

If you fetched the above metrics you will receive a result like the following, which will give you all goal metrics in the active time:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
    "meta": [
        [
            "label",
            "String"
        ],
        [
            "count(value)",
            "UInt64"
        ],
        [
            "sum(value)",
            "Nullable(Float64)"
        ]
    ],
    "data": [
        [
            "2870f654-c6a7-11e6-8a67-60f81db030fe",  // Your Goal
            17, // How many times this goal appeared
            17.0 // The sum of the value. If this has unique values it will sum them up.
        ],
        [
            "1573a689-c6a7-11e6-8a67-60f81db030fe",  // Your Goal
            68, // How many times this goal appeared
            1400.0 // The sum of the value. If this has unique values it will sum them up.
        ]
        ... // All goals within your timespan
    ]
}

Conclusion

In this tutorial we have learnt how to fetch all goal metrics in a specific timespan. If you have more questions feel free to E-Mail support@giosg.com or chat with us.