Skip to content

Fetching counts of used tags from User Chat Statistics

Overview

Giosg platform provides APIs for fetching metrics from the chats the users within your organization had. This tutorial guides you through requesting counts of used tags which User Chat Statistics provides you, 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”

Which metrics can I request?

This tutorial focuses on used tags counts in rooms and the organization. Giosg has a lot more metrics that we provide and which you can learn more from here

Queries

Fetch the allowed tags for the organization

Request URL: GET https://service.giosg.com/api/v5/orgs/<org_id>/allowed_tags

The response will contain all the tags that are allowed to use in organizations rooms.

Response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
    "next": "<next_page_url>",
    "previous": null,
    "results": [
        {
            "name": "Tag name",
            "hashed_name": "<hashed_name>",
            "created_at": "<created_at>",
            "room_id": "<room_id>"
        }
    ]
}

The results array will contain all the allowed tags for this organization.

This part is important since the “added” and “removed” -events which will tell the tag count does not include the human readable name of the tag but instead the label field will contain the hashed_name value. With the result of this query the human readable names can be bound to the event counts.

Fetch the added tag events for the organization

This query will return the added tags and the count how many times each tag was added.

Note: Remember to set the “start” and “end” properties in the query to match the wanted time span.

Request URL: POST https://service.giosg.com/api/events/v2/orgs/<organization_id>/fetch

Request body:

 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
{
    "granularity": "all",
    "group_by": [
        "label"
    ],
    "sources": [
        "trusted"
    ],
    "interval": {
        "start": "2020-10-29T00:00:00.000+02:00",
        "end": "2020-10-30T23:59:59.999+02:00",
        "time_zone": "Europe/Helsinki"
    },
    "vendor": "com.giosg.chat",
    "aggregations": [
        "count"
    ],
    "filters": {
        "type": "and",
        "fields": [
            {
                "type": "selector",
                "dimension": "category",
                "value": "chat_session_tag"
            },
            {
                "type": "selector",
                "dimension": "action",
                "value": "added"
            }
        ]
    }
}

Response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    "fields": [
        {
            "name": "timestamp",
            "type": "dimension"
        },
        {
            "name": "label",
            "type": "dimension"
        },
        {
            "name": "count",
            "type": "metric"
        }
    ],
    "data": [
        [
            "2020-10-28T22:00:00.000Z",
            "12eb0d741c1f38bec0e6d2a1010be5e25df50059",
            1
        ],
    ]
}

The “data” -array contains the values for properties defined in the “fields” -array. For example the index 0 in the first item in “data” -array is the value of timestamp etc.

Note: To get the human readable label, bind the tags from 1. steps’ response.

Fetch the removed tag events for the organization

This query will return the removed tags and the count how many times each tag was removed.

Note: Remember to set the “start” and “end” properties in the query to match the wanted time span.

Request URL: POST https://service.giosg.com/api/events/v2/orgs/<organization_id>/fetch

Request body:

 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
{
    "granularity": "all",
    "group_by": [
        "label"
    ],
    "sources": [
        "trusted"
    ],
    "interval": {
        "start": "2020-10-29T00:00:00.000+02:00",
        "end": "2020-10-30T23:59:59.999+02:00",
        "time_zone": "Europe/Helsinki"
    },
    "vendor": "com.giosg.chat",
    "aggregations": [
        "count"
    ],
    "filters": {
        "type": "and",
        "fields": [
            {
                "type": "selector",
                "dimension": "category",
                "value": "chat_session_tag"
            },
            {
                "type": "selector",
                "dimension": "action",
                "value": "removed"
            }
        ]
    }
}

Response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    "fields": [
        {
            "name": "timestamp",
            "type": "dimension"
        },
        {
            "name": "label",
            "type": "dimension"
        },
        {
            "name": "count",
            "type": "metric"
        }
    ],
    "data": [
        [
            "2020-10-28T22:00:00.000Z",
            "12eb0d741c1f38bec0e6d2a1010be5e25df50059",
            1
        ],
    ]
}

The “data” -array contains the values for properties defined in the “fields” -array. For example the index 0 in the first item in “data” -array is the value of timestamp etc.

Note: To get the human readable label, bind the tags from 1. steps’ response.

Fetch the added tag events for certain room

This query will return the added tags and the count how many times each tag was added.

Note: Remember to set the “start” and “end” properties in the query to match the wanted time span.

Request URL: POST https://service.giosg.com/api/events/v2/orgs/<organization_id>/fetch

Request body:

 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
{
    "granularity": "all",
    "group_by": [
        "label"
    ],
    "sources": [
        "trusted"
    ],
    "interval": {
        "start": "2020-10-29T00:00:00.000+02:00",
        "end": "2020-10-30T23:59:59.999+02:00",
        "time_zone": "Europe/Helsinki"
    },
    "vendor": "com.giosg.chat",
    "aggregations": [
        "count"
    ],
    "filters": {
        "type": "and",
        "fields": [
            {
                "type": "selector",
                "dimension": "category",
                "value": "chat_session_tag"
            },
            {
                "type": "selector",
                "dimension": "action",
                "value": "added"
            },
            {
                "type": "selector",
                "dimension": "dim1",
                "value": "d792e948-eb9d-11e7-b6ec-00163ea17fd8"
            }
        ]
    }
}

Response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    "fields": [
        {
            "name": "timestamp",
            "type": "dimension"
        },
        {
            "name": "label",
            "type": "dimension"
        },
        {
            "name": "count",
            "type": "metric"
        }
    ],
    "data": [
        [
            "2020-10-28T22:00:00.000Z",
            "<room_id>",
            1
        ],
    ]
}

The “data” -array contains the values for properties defined in the “fields” -array. For example the index 0 in the first item in “data” -array is the value of timestamp etc.

Note: To get the human readable label, bind the tags from 1. steps’ response.

Fetch the removed tag events for certain room

This query will return the removed tags and the count how many times each tag was added.

Note: Remember to set the “start” and “end” properties in the query to match the wanted time span.

Request URL: POST https://service.giosg.com/api/events/v2/orgs/<organization_id>/fetch

Request body:

 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
{
    "granularity": "all",
    "group_by": [
        "label"
    ],
    "sources": [
        "trusted"
    ],
    "interval": {
        "start": "2020-10-29T00:00:00.000+02:00",
        "end": "2020-10-30T23:59:59.999+02:00",
        "time_zone": "Europe/Helsinki"
    },
    "vendor": "com.giosg.chat",
    "aggregations": [
        "count"
    ],
    "filters": {
        "type": "and",
        "fields": [
            {
                "type": "selector",
                "dimension": "category",
                "value": "chat_session_tag"
            },
            {
                "type": "selector",
                "dimension": "action",
                "value": "added"
            },
            {
                "type": "selector",
                "dimension": "dim1",
                "value": "<room_id>"
            }
        ]
    }
}

Response:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{
    "fields": [
        {
        "name": "timestamp",
        "type": "dimension"
        },
        {
        "name": "label",
        "type": "dimension"
        },
        {
        "name": "count",
        "type": "metric"
        }
    ],
    "data": [
        [
        "2020-10-28T22:00:00.000Z",
        "12eb0d741c1f38bec0e6d2a1010be5e25df50059",
        1
        ],
    ]
}

The “data” -array contains the values for properties defined in the “fields” -array. For example the index 0 in the first item in “data” -array is the value of timestamp etc.

Note: To get the human readable label, bind the tags from 1. steps’ response.

Conclusion

In this tutorial we have learnt how to request counts of used tags from Giosg Reporting, and got some metrics that can be used further by your own IT in your own products or reports.

Endpoints used in this tutorial

  1. https://service.giosg.com/api/v5/orgs/<org_id>/allowed_tags
  2. https://api.giosg.com/api/events/v2/orgs/<organization_id>/fetch