# Get Things Services Usage Report

Please note that in order to get Services Usage Report you will need to run multiple API commands:

1. [Create Report template](#1st-api-command-create-report-template)
2. [Generate Report using the created template](#2nd-api-command-generate-report-using-the-created-template)
3. [Get CSV Report location](#3rd-api-command-get-csv-report-location)
4. [Download CSV Report informaiton](#4th-api-command-download-csv-report-information)

## 1st API command - Create Report template

## Create Report template

<mark style="color:green;">`POST`</mark> `https://console.monogoto.io/report-template`

#### Headers

| Name                                          | Type   | Description               |
| --------------------------------------------- | ------ | ------------------------- |
| YOUR\_TOKEN<mark style="color:red;">\*</mark> | String | Your authentication token |

#### Request Body

| Name                                                  | Type   | Description                                                                                                                              |
| ----------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| REPORT\_NAME<mark style="color:red;">\*</mark>        | String | Report name                                                                                                                              |
| REPORT\_DESCRIPTION<mark style="color:red;">\*</mark> | String | Report description                                                                                                                       |
| START\_DATE<mark style="color:red;">\*</mark>         | String | Start date of the Report in epoch format with milliseconds. [You can use converter following this link](https://www.epochconverter.com/) |
| END\_DATE<mark style="color:red;">\*</mark>           | String | End date of the Report in epoch format with milliseconds. [You can use converter following this link](https://www.epochconverter.com/)   |

{% tabs %}
{% tab title="200: OK OK" %}

```javascript
{
    Newly created Report Template ID
}
```

{% endtab %}

{% tab title="400: Bad Request Invalid Input Data" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}

{% tab title="401: Unauthorized Unauthorized" %}

```javascript
{
    Unauthorized
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    "message": "string"
}
```

{% endtab %}
{% endtabs %}

### Example using **cURL**:

```bash
curl -X POST \
     --url "https://console.monogoto.io/report-template/" \
     -H "accept: application/json" \
     -H "Authorization: Bearer {YOUR_TOKEN}" \
     -d "{ \"Name\": \"{REPORT_NAME}\", \"Description\": \"{REPORT_DESCRIPTION}\", \"GroupBy\": \"servingNetwork\", \"rateByCurrentPricePlan\": true, \"ReportType\": \"rating\", \"ReportPeriod\": { \"startDate\": {START_DATE}, \"endDate\": {END_DATE}}}" \
```

**Example of request**

```bash
curl -X POST \
     --url "https://console.monogoto.io/report-template/" \
     -H "accept: application/json" \
     -H "Authorization: Bearer eyJhb6IkpXVCJ9.eyJSb2xlIjoiVXN4lclByb2ZpbGVJZF9kZGM2MThhNC0wNTI1LTQ2MmUtYWN3NzhhMGQxYmbSI6Im4zgFkbWluIiwiQ3VzdG9tsbCwiVXNlcklkIjoiVklkXzg5Yj5Y2OGEyUtNDQThhLTEzZjA0MzJhZDE3YyINTAzgZmUtZGI51My00ZjRiLTktN2U5Yjc0ZWU1ZThlIiwiaWNzM3MjI5L2MDY3NTE2Mjl9.99aSLzP7kTgK6TZGW-xalrMu0GkW6viunt3XxbNng" \
     -d "{ \"Name\": \"September_report\", \"Description\": \"September_report\", \"GroupBy\": \"servingNetwork\", \"rateByCurrentPricePlan\": true, \"ReportType\": \"rating\", \"ReportPeriod\": { \"startDate\": 1661979600000, \"endDate\": 1664571599000}}" \
```

Example of response to our request:

```
ReportTemplateId_a14901d4b-7691-4548-8110-72abcba0be22
```

{% openapi src="/files/lqgrtNg1pOcbxIdacwgh" path="/report-template" method="post" %}
[JPU\_CustomerAPIV\_Without\_Test it.yaml](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FXtNpEMk17YOUrC39Cmvr%2FJPU_CustomerAPIV_Without_Test%20it.yaml?alt=media\&token=09b74b38-dd09-4edc-8f98-4df792b3c986)
{% endopenapi %}

## 2nd API command - Generate Report using the created template

## Generate Report using the created template

<mark style="color:green;">`POST`</mark> `https://console.monogoto.io/report-history/{reportTemplateId}`

#### Path Parameters

| Name                                                   | Type   | Description                                                                                                                             |
| ------------------------------------------------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| REPORT\_TEMPLATE\_ID<mark style="color:red;">\*</mark> | String | Report template ID, it can be seen in response of [Report template creation (1st API command)](#1st-api-command-create-report-template) |

#### Headers

| Name                                          | Type   | Description               |
| --------------------------------------------- | ------ | ------------------------- |
| YOUR\_TOKEN<mark style="color:red;">\*</mark> | String | Your authentication token |

{% tabs %}
{% tab title="200: OK ok" %}

```javascript
Newly generated Report History ID
```

{% endtab %}

{% tab title="400: Bad Request Invalid Input Data" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}

{% tab title="401: Unauthorized Unauthorized" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal Server Error" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Please note that this API may take a while to be completed if you have a lot of Things (SIM) in your Monogoto account.
{% endhint %}

### Example using **cURL**:

```bash
curl -X POST \
     --url "https://console.monogoto.io/report-history/{REPORT_TEMPLATE_ID}" \
     -H "accept: application/json" \
     -H "Authorization: Bearer {YOUR_TOKEN}" \
```

**Example of request**

```bash
curl -X POST \
     --url "https://console.monogoto.io/report-history/ReportTemplateId_a14901d4b-7691-4548-8110-72abcba0be22" \
     -H "accept: application/json" \
     -H "Authorization: Bearer eyJhb6IkpXVCJ9.eyJSb2xlIjoiVXN4lclByb2ZpbGVJZF9kZGM2MThhNC0wNTI1LTQ2MmUtYWN3NzhhMGQxYmbSI6Im4zgFkbWluIiwiQ3VzdG9tsbCwiVXNlcklkIjoiVklkXzg5Yj5Y2OGEyUtNDQThhLTEzZjA0MzJhZDE3YyINTAzgZmUtZGI51My00ZjRiLTktN2U5Yjc0ZWU1ZThlIiwiaWNzM3MjI5L2MDY3NTE2Mjl9.99aSLzP7kTgK6TZGW-xalrMu0GkW6viunt3XxbNng" \
```

Example of response to our request:

```
ReportHistoryId_611bac7b-abc9-4c18-9cbb-a497889180b7
```

{% openapi src="/files/lqgrtNg1pOcbxIdacwgh" path="/report-history/{reportTemplateId}" method="post" %}
[JPU\_CustomerAPIV\_Without\_Test it.yaml](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FXtNpEMk17YOUrC39Cmvr%2FJPU_CustomerAPIV_Without_Test%20it.yaml?alt=media\&token=09b74b38-dd09-4edc-8f98-4df792b3c986)
{% endopenapi %}

## 3rd API command - Get CSV Report location

## Get CSV Report location

<mark style="color:blue;">`GET`</mark> `https://console.monogoto.io/report-history/byTemplate`

#### Headers

| Name                                          | Type   | Description               |
| --------------------------------------------- | ------ | ------------------------- |
| YOUR\_TOKEN<mark style="color:red;">\*</mark> | String | Your authentication token |

{% tabs %}
{% tab title="200: OK Array of Report Histories" %}

```javascript
[
  {
    "Name": "string",
    "ReportTemplateDescription": "string",
    "ReportTemplateName": "string",
    "FilterBy": "string",
    "FilterByItems": {
      "CustomerId": [
        null
      ],
      "ThingsGroupId": [
        null
      ],
      "ThingId": [
        null
      ],
      "TagId": [
        null
      ]
    },
    "GroupBy": "string",
    "GroupByInterval": "string",
    "ReportType": "string",
    "ReportPeriod": {
      "startDate": "2022-10-04T12:56:06.957Z",
      "endDate": "2022-10-04T12:56:06.957Z"
    },
    "CustomerId": "string",
    "OrganizationId": "string",
    "ReportTemplateId": "string",
    "ReportHistoryId": "string",
    "DateCreated": "2022-10-04T12:56:06.957Z",
    "DateModified": "2022-10-04T12:56:06.957Z",
    "Type": "string"
  }
]
```

{% endtab %}

{% tab title="401: Unauthorized Unauthorized" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal Server Error" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}
{% endtabs %}

### Example using **cURL**:

```bash
curl -X GET \
     --url "https://console.monogoto.io/report-history/report-history/byTemplate" \
     -H "accept: application/json" \
     -H "Authorization: Bearer {YOUR_TOKEN}" \
```

**Example of request**

```bash
curl -X GET \
     --url "https://console.monogoto.io/report-history/report-history/byTemplate" \
     -H "accept: application/json" \
     -H "Authorization: Bearer eyJhb6IkpXVCJ9.eyJSb2xlIjoiVXN4lclByb2ZpbGVJZF9kZGM2MThhNC0wNTI1LTQ2MmUtYWN3NzhhMGQxYmbSI6Im4zgFkbWluIiwiQ3VzdG9tsbCwiVXNlcklkIjoiVklkXzg5Yj5Y2OGEyUtNDQThhLTEzZjA0MzJhZDE3YyINTAzgZmUtZGI51My00ZjRiLTktN2U5Yjc0ZWU1ZThlIiwiaWNzM3MjI5L2MDY3NTE2Mjl9.99aSLzP7kTgK6TZGW-xalrMu0GkW6viunt3XxbNng" \
```

{% hint style="info" %}
In the response to our request, you will need to find a Report matching our [Report template ID](#1st-api-command-create-report-template) or [Report history ID](#2nd-api-command-generate-report-using-the-created-template). Then take **csvPath** and use it in the [4th API command](#4th-api-command-download-csv-report-information).
{% endhint %}

Example of response to our request:

```html
{
  "dbResponse": [
    {
      "ReportHistoryId": "ReportHistoryId_611bac7b-abc9-4c18-9cbb-a497889180b7",
      "ReportTemplateId": "ReportTemplateId_a14901d4b-7691-4548-8110-72abcba0be22",
      "ReportType": "rating",
      "FilterBy": "none",
      "FilterByItems": {},
      "OrganizationId": "OrganizationId_2ds578d7d-abc9-4123-acbb-1ec67a98b01a",
      "CustomerId": "cid_eb426486-488a-4f44-9c6d-3627a66150cb",
      "GroupBy": "servingNetwork",
      "GroupByInterval": "d",
      "ReportTemplateName": "September_report",
      "ReportTemplateDescription": "September_report",
      "ReportPeriod": {
        "startDate": 1661979600000,
        "endDate": 1664571599000
      },
      "csvPath": "/efs/reports/csv/2022/10/4/Report_September_report_#8d351.csv",
      "pdfPath": "/efs/reports/pdf/2022/10/4/Report_September_report_#8d351.pdf",
      "ReportData": null,
      "Name": "Report September_report #8d351",
      "rateByCurrentPricePlan": false,
      "Type": "ReportHistory",
      "DateCreated": 1664887341012
    }
```

{% openapi src="/files/lqgrtNg1pOcbxIdacwgh" path="/report-history/byTemplate" method="get" %}
[JPU\_CustomerAPIV\_Without\_Test it.yaml](https://3922449203-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M0mPxGpottOEfcucXOR%2Fuploads%2FXtNpEMk17YOUrC39Cmvr%2FJPU_CustomerAPIV_Without_Test%20it.yaml?alt=media\&token=09b74b38-dd09-4edc-8f98-4df792b3c986)
{% endopenapi %}

## 4th API command - Download CSV Report information

## Download CSV Report information

<mark style="color:blue;">`GET`</mark> `https://console.monogoto.io /report-history/downloadReport/csv/{csvPath}`

#### Path Parameters

| Name                                        | Type   | Description                                                                                                    |
| ------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------- |
| CSV\_PATH<mark style="color:red;">\*</mark> | String | CSV file path that was received in [3rd  API to get Report location](#3rd-api-command-get-csv-report-location) |

#### Headers

| Name                                          | Type   | Description               |
| --------------------------------------------- | ------ | ------------------------- |
| YOUR\_TOKEN<mark style="color:red;">\*</mark> | String | Your authentication token |

{% tabs %}
{% tab title="200: OK ok" %}

```javascript
The CSV contents of the reports
```

{% endtab %}

{% tab title="400: Bad Request Invalid Input Data" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}

{% tab title="401: Unauthorized Unauthorized" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Internal Server Error" %}

```javascript
{
    "message": "string"
}
```

{% endtab %}
{% endtabs %}

### Example using **cURL**:

```bash
curl -X GET \
     --url "https://console.monogoto.io/https://console.monogoto.io /report-history/downloadReport/csv/{csvPath}" \
     -H "accept: application/json" \
     -H "Authorization: Bearer {YOUR_TOKEN}" \
```

{% hint style="warning" %}
Please note that in **csvPath** some symbols will need to be converted to numbers and letters:

**/** - will be need to be replaced with **%2F**

**#** - will need to be replaced with **%23**

**Example of csvPath:**

/efs/reports/csv/2022/10/4/Report\_September\_report\_#8d351.csv

**Example after csvPath symbols were changed to code values:**

%2Fefs%2Freports%2Fcsv%2F2022%2F10%2F4%2FReport\_September\_report\_%238d351.csv
{% endhint %}

**Example of request**

```bash
curl -X GET \
     --url "https://console.monogoto.io/https://console.monogoto.io /report-history/downloadReport/csv/%2Fefs%2Freports%2Fcsv%2F2022%2F10%2F4%2FReport_September_report_%238d351.csv" \
     -H "accept: application/json" \
     -H "Authorization: Bearer eyJhb6IkpXVCJ9.eyJSb2xlIjoiVXN4lclByb2ZpbGVJZF9kZGM2MThhNC0wNTI1LTQ2MmUtYWN3NzhhMGQxYmbSI6Im4zgFkbWluIiwiQ3VzdG9tsbCwiVXNlcklkIjoiVklkXzg5Yj5Y2OGEyUtNDQThhLTEzZjA0MzJhZDE3YyINTAzgZmUtZGI51My00ZjRiLTktN2U5Yjc0ZWU1ZThlIiwiaWNzM3MjI5L2MDY3NTE2Mjl9.99aSLzP7kTgK6TZGW-xalrMu0GkW6viunt3XxbNng" \
```

Example of response to our request showing CSV file information:

```html
Thing Name,IMSI,MSISDN,Roaming Partner,Data,SMS,MO SMS,MT SMS,Voice,MO VOICE,MT VOICE,Total Before Credit,Credit,Total
"ICCID 8912372646888991, 8912372646888991",1234567891011,+420123456789,Bite , 140.25 MB,,,,,,,,,0.9677
"ICCID 8912372646888991, 8912372646888991",1234567891011,+420123456789,,140.25 MB,,,,,,,0.9677,0.0000,0.9677
"ICCID 8912372646888992, 8912372646888992",1234567891012,+420123456790,OMNITEL , 64.34 MB,,,,,,,,,0.4504
"ICCID 8912372646888992, 8912372646888992",1234567891012,+420123456790,,64.34 MB,,,,,,,0.4504,0.0000,0.4504
"ICCID 8912372646888993, 8912372646888993",1234567891013,+420123456791,Bite , 28.9 MB, 2,,,,,,,,0.1994
"ICCID 8912372646888993, 8912372646888993",1234567891013,+420123456791,,28.9 MB,,,2,,,,0.1994,0.0000,0.1994
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.monogoto.io/developer/api/things/get-things-services-usage-report.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
