Get Togai Metrics
curl --request POST \
--url https://api.togai.com/metrics \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"startTime": "2017-07-21T00:00:00Z",
"endTime": "2017-07-22T00:00:00Z",
"metricQueries": [
{
"id": "m1",
"name": "EVENTS",
"aggregationPeriod": "DAY",
"filters": [
{
"fieldName": "ACCOUNT_ID",
"fieldValues": [
"account#1"
]
},
{
"fieldName": "CUSTOMER_ID",
"fieldValues": [
"customer#1"
]
},
{
"fieldName": "EVENT_STATUS",
"fieldValues": [
"PROCESSED"
]
}
]
},
{
"id": "m2",
"name": "USAGE",
"aggregationPeriod": "MONTH",
"filters": [
{
"fieldName": "CUSTOMER_ID",
"fieldValues": [
"customer#1"
]
}
]
}
]
}
'import requests
url = "https://api.togai.com/metrics"
payload = {
"startTime": "2017-07-21T00:00:00Z",
"endTime": "2017-07-22T00:00:00Z",
"metricQueries": [
{
"id": "m1",
"name": "EVENTS",
"aggregationPeriod": "DAY",
"filters": [
{
"fieldName": "ACCOUNT_ID",
"fieldValues": ["account#1"]
},
{
"fieldName": "CUSTOMER_ID",
"fieldValues": ["customer#1"]
},
{
"fieldName": "EVENT_STATUS",
"fieldValues": ["PROCESSED"]
}
]
},
{
"id": "m2",
"name": "USAGE",
"aggregationPeriod": "MONTH",
"filters": [
{
"fieldName": "CUSTOMER_ID",
"fieldValues": ["customer#1"]
}
]
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
startTime: '2017-07-21T00:00:00Z',
endTime: '2017-07-22T00:00:00Z',
metricQueries: [
{
id: 'm1',
name: 'EVENTS',
aggregationPeriod: 'DAY',
filters: [
{fieldName: 'ACCOUNT_ID', fieldValues: ['account#1']},
{fieldName: 'CUSTOMER_ID', fieldValues: ['customer#1']},
{fieldName: 'EVENT_STATUS', fieldValues: ['PROCESSED']}
]
},
{
id: 'm2',
name: 'USAGE',
aggregationPeriod: 'MONTH',
filters: [{fieldName: 'CUSTOMER_ID', fieldValues: ['customer#1']}]
}
]
})
};
fetch('https://api.togai.com/metrics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.togai.com/metrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'startTime' => '2017-07-21T00:00:00Z',
'endTime' => '2017-07-22T00:00:00Z',
'metricQueries' => [
[
'id' => 'm1',
'name' => 'EVENTS',
'aggregationPeriod' => 'DAY',
'filters' => [
[
'fieldName' => 'ACCOUNT_ID',
'fieldValues' => [
'account#1'
]
],
[
'fieldName' => 'CUSTOMER_ID',
'fieldValues' => [
'customer#1'
]
],
[
'fieldName' => 'EVENT_STATUS',
'fieldValues' => [
'PROCESSED'
]
]
]
],
[
'id' => 'm2',
'name' => 'USAGE',
'aggregationPeriod' => 'MONTH',
'filters' => [
[
'fieldName' => 'CUSTOMER_ID',
'fieldValues' => [
'customer#1'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.togai.com/metrics"
payload := strings.NewReader("{\n \"startTime\": \"2017-07-21T00:00:00Z\",\n \"endTime\": \"2017-07-22T00:00:00Z\",\n \"metricQueries\": [\n {\n \"id\": \"m1\",\n \"name\": \"EVENTS\",\n \"aggregationPeriod\": \"DAY\",\n \"filters\": [\n {\n \"fieldName\": \"ACCOUNT_ID\",\n \"fieldValues\": [\n \"account#1\"\n ]\n },\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n },\n {\n \"fieldName\": \"EVENT_STATUS\",\n \"fieldValues\": [\n \"PROCESSED\"\n ]\n }\n ]\n },\n {\n \"id\": \"m2\",\n \"name\": \"USAGE\",\n \"aggregationPeriod\": \"MONTH\",\n \"filters\": [\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.togai.com/metrics")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"startTime\": \"2017-07-21T00:00:00Z\",\n \"endTime\": \"2017-07-22T00:00:00Z\",\n \"metricQueries\": [\n {\n \"id\": \"m1\",\n \"name\": \"EVENTS\",\n \"aggregationPeriod\": \"DAY\",\n \"filters\": [\n {\n \"fieldName\": \"ACCOUNT_ID\",\n \"fieldValues\": [\n \"account#1\"\n ]\n },\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n },\n {\n \"fieldName\": \"EVENT_STATUS\",\n \"fieldValues\": [\n \"PROCESSED\"\n ]\n }\n ]\n },\n {\n \"id\": \"m2\",\n \"name\": \"USAGE\",\n \"aggregationPeriod\": \"MONTH\",\n \"filters\": [\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.togai.com/metrics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"startTime\": \"2017-07-21T00:00:00Z\",\n \"endTime\": \"2017-07-22T00:00:00Z\",\n \"metricQueries\": [\n {\n \"id\": \"m1\",\n \"name\": \"EVENTS\",\n \"aggregationPeriod\": \"DAY\",\n \"filters\": [\n {\n \"fieldName\": \"ACCOUNT_ID\",\n \"fieldValues\": [\n \"account#1\"\n ]\n },\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n },\n {\n \"fieldName\": \"EVENT_STATUS\",\n \"fieldValues\": [\n \"PROCESSED\"\n ]\n }\n ]\n },\n {\n \"id\": \"m2\",\n \"name\": \"USAGE\",\n \"aggregationPeriod\": \"MONTH\",\n \"filters\": [\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"id": "m1",
"name": "EVENTS",
"data": [
{
"timestamps": [
"2017-07-21T00:00:00Z",
"2017-07-22T00:00:00Z"
],
"metricValues": [
53,
32
]
}
]
},
{
"id": "m2",
"name": "USAGE",
"data": [
{
"timestamps": [
"2017-07-01T00:00:00Z"
],
"metricValues": [
123.45
]
}
]
}
]
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "<Reason message>"
}Metrics
Get Togai Metrics
Togai Metrics API allows you to fetch different metrics from Events, Usage Meters and PricePlans with multiple queryable options. A single request can query up to five metrics. Single response can contain a maximum of 300 data points.
POST
/
metrics
Get Togai Metrics
curl --request POST \
--url https://api.togai.com/metrics \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"startTime": "2017-07-21T00:00:00Z",
"endTime": "2017-07-22T00:00:00Z",
"metricQueries": [
{
"id": "m1",
"name": "EVENTS",
"aggregationPeriod": "DAY",
"filters": [
{
"fieldName": "ACCOUNT_ID",
"fieldValues": [
"account#1"
]
},
{
"fieldName": "CUSTOMER_ID",
"fieldValues": [
"customer#1"
]
},
{
"fieldName": "EVENT_STATUS",
"fieldValues": [
"PROCESSED"
]
}
]
},
{
"id": "m2",
"name": "USAGE",
"aggregationPeriod": "MONTH",
"filters": [
{
"fieldName": "CUSTOMER_ID",
"fieldValues": [
"customer#1"
]
}
]
}
]
}
'import requests
url = "https://api.togai.com/metrics"
payload = {
"startTime": "2017-07-21T00:00:00Z",
"endTime": "2017-07-22T00:00:00Z",
"metricQueries": [
{
"id": "m1",
"name": "EVENTS",
"aggregationPeriod": "DAY",
"filters": [
{
"fieldName": "ACCOUNT_ID",
"fieldValues": ["account#1"]
},
{
"fieldName": "CUSTOMER_ID",
"fieldValues": ["customer#1"]
},
{
"fieldName": "EVENT_STATUS",
"fieldValues": ["PROCESSED"]
}
]
},
{
"id": "m2",
"name": "USAGE",
"aggregationPeriod": "MONTH",
"filters": [
{
"fieldName": "CUSTOMER_ID",
"fieldValues": ["customer#1"]
}
]
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
startTime: '2017-07-21T00:00:00Z',
endTime: '2017-07-22T00:00:00Z',
metricQueries: [
{
id: 'm1',
name: 'EVENTS',
aggregationPeriod: 'DAY',
filters: [
{fieldName: 'ACCOUNT_ID', fieldValues: ['account#1']},
{fieldName: 'CUSTOMER_ID', fieldValues: ['customer#1']},
{fieldName: 'EVENT_STATUS', fieldValues: ['PROCESSED']}
]
},
{
id: 'm2',
name: 'USAGE',
aggregationPeriod: 'MONTH',
filters: [{fieldName: 'CUSTOMER_ID', fieldValues: ['customer#1']}]
}
]
})
};
fetch('https://api.togai.com/metrics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.togai.com/metrics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'startTime' => '2017-07-21T00:00:00Z',
'endTime' => '2017-07-22T00:00:00Z',
'metricQueries' => [
[
'id' => 'm1',
'name' => 'EVENTS',
'aggregationPeriod' => 'DAY',
'filters' => [
[
'fieldName' => 'ACCOUNT_ID',
'fieldValues' => [
'account#1'
]
],
[
'fieldName' => 'CUSTOMER_ID',
'fieldValues' => [
'customer#1'
]
],
[
'fieldName' => 'EVENT_STATUS',
'fieldValues' => [
'PROCESSED'
]
]
]
],
[
'id' => 'm2',
'name' => 'USAGE',
'aggregationPeriod' => 'MONTH',
'filters' => [
[
'fieldName' => 'CUSTOMER_ID',
'fieldValues' => [
'customer#1'
]
]
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.togai.com/metrics"
payload := strings.NewReader("{\n \"startTime\": \"2017-07-21T00:00:00Z\",\n \"endTime\": \"2017-07-22T00:00:00Z\",\n \"metricQueries\": [\n {\n \"id\": \"m1\",\n \"name\": \"EVENTS\",\n \"aggregationPeriod\": \"DAY\",\n \"filters\": [\n {\n \"fieldName\": \"ACCOUNT_ID\",\n \"fieldValues\": [\n \"account#1\"\n ]\n },\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n },\n {\n \"fieldName\": \"EVENT_STATUS\",\n \"fieldValues\": [\n \"PROCESSED\"\n ]\n }\n ]\n },\n {\n \"id\": \"m2\",\n \"name\": \"USAGE\",\n \"aggregationPeriod\": \"MONTH\",\n \"filters\": [\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n }\n ]\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.togai.com/metrics")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"startTime\": \"2017-07-21T00:00:00Z\",\n \"endTime\": \"2017-07-22T00:00:00Z\",\n \"metricQueries\": [\n {\n \"id\": \"m1\",\n \"name\": \"EVENTS\",\n \"aggregationPeriod\": \"DAY\",\n \"filters\": [\n {\n \"fieldName\": \"ACCOUNT_ID\",\n \"fieldValues\": [\n \"account#1\"\n ]\n },\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n },\n {\n \"fieldName\": \"EVENT_STATUS\",\n \"fieldValues\": [\n \"PROCESSED\"\n ]\n }\n ]\n },\n {\n \"id\": \"m2\",\n \"name\": \"USAGE\",\n \"aggregationPeriod\": \"MONTH\",\n \"filters\": [\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n }\n ]\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.togai.com/metrics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"startTime\": \"2017-07-21T00:00:00Z\",\n \"endTime\": \"2017-07-22T00:00:00Z\",\n \"metricQueries\": [\n {\n \"id\": \"m1\",\n \"name\": \"EVENTS\",\n \"aggregationPeriod\": \"DAY\",\n \"filters\": [\n {\n \"fieldName\": \"ACCOUNT_ID\",\n \"fieldValues\": [\n \"account#1\"\n ]\n },\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n },\n {\n \"fieldName\": \"EVENT_STATUS\",\n \"fieldValues\": [\n \"PROCESSED\"\n ]\n }\n ]\n },\n {\n \"id\": \"m2\",\n \"name\": \"USAGE\",\n \"aggregationPeriod\": \"MONTH\",\n \"filters\": [\n {\n \"fieldName\": \"CUSTOMER_ID\",\n \"fieldValues\": [\n \"customer#1\"\n ]\n }\n ]\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"results": [
{
"id": "m1",
"name": "EVENTS",
"data": [
{
"timestamps": [
"2017-07-21T00:00:00Z",
"2017-07-22T00:00:00Z"
],
"metricValues": [
53,
32
]
}
]
},
{
"id": "m2",
"name": "USAGE",
"data": [
{
"timestamps": [
"2017-07-01T00:00:00Z"
],
"metricValues": [
123.45
]
}
]
}
]
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "<string>"
}{
"message": "<Reason message>"
}MetricQuery: Allowed field combinations
MetricQuery.configs
MetricQuery.configs
| Metric Name | Config Key | Allowed Values | Default value | Description |
|---|---|---|---|---|
REVENUE | CURRENCY | BASE or INVOICE | BASE | currency to return the revenue in |
REVENUE_FOR_CYCLE | CURRENCY | BASE or INVOICE | BASE | currency to return the revenue in |
MetricQuery.filters
MetricQuery.filters
| Metric Name | FilterEntry Name | Allowed groupBy fields | Default Values | Allowed Values |
|---|---|---|---|---|
EVENTS | ACCOUNT_ID | ACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME, | None | *<one or more valid account IDs> |
EVENTS | CUSTOMER_ID | ACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME, | None | *<one or more valid customer IDs> |
EVENTS | SCHEMA_NAME | ACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME, | None | *<at most one valid schema names> |
EVENTS | EVENT_STATUS | ACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME, | [PROCESSED, UNPROCESSED] | oneOrMoreOf PROCESSED, UNPROCESSED, IN_PROGRESS |
USAGE | ACCOUNT_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid account IDs> |
USAGE | CUSTOMER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid customer IDs> |
USAGE | USAGE_METER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid usage meter name> |
REVENUE | ACCOUNT_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid account IDs> |
REVENUE | CUSTOMER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid customer IDs> |
REVENUE | USAGE_METER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid usage meter name> |
USAGE_FOR_CYCLE | ACCOUNT_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid account IDs> |
USAGE_FOR_CYCLE | CUSTOMER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid customer IDs> |
USAGE_FOR_CYCLE | USAGE_METER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid usage meter name> |
REVENUE_FOR_CYCLE | ACCOUNT_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid account IDs> |
REVENUE_FOR_CYCLE | CUSTOMER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid customer IDs> |
REVENUE_FOR_CYCLE | USAGE_METER_ID | ACCOUNT_ID, USAGE_METER_ID, CUSTOMER_ID | None | *<one or more valid usage meter name> |
Notes on `USAGE_FOR_CYCLE` and `REVENUE_FOR_CYCLE`
Notes on `USAGE_FOR_CYCLE` and `REVENUE_FOR_CYCLE`
Storage
The*_FOR_CYCLE metrics in Togai are stored against the pricing cycle start date of accounts based on their pricing schedules.For instance, metrics of an account having a MONTHLY pricing cycle configued to invoice on 5th of every month, metrics are stored as follows.| PricingCycleStartDate | Usage/RevenueForCycle |
|---|---|
2020-01-05T00:00:00Z | 1000 |
2020-02-05T00:00:00Z | 1200 |
2020-03-05T00:00:00Z | 1200 |
2020-03-15, metrics are stored as follows.| PricingCycleStartDate | Usage/RevenueForCycle |
|---|---|
2020-01-05T00:00:00Z | 1000 |
2020-02-05T00:00:00Z | 1200 |
2020-03-05T00:00:00Z | 1250 |
2020-03-15T00:00:00Z | 600 |
2020-04-01T00:00:00Z | 1300 |
2020-05-01T00:00:00Z | 1300 |
Querying
Now, in order to query the*_FOR_CYCLE metrics for any pricing cycle, make sure that the PricingCycleStartDate lies within startTime (inclusive) and endTime (exclusive).Example, for metrics query with startTime as 2020-02-15T00:00:00Z and endTime as 2020-04-01T00:00:00Z results contain the data from below records.| PricingCycleStartDate | Usage/RevenueForCycle |
|---|---|
2020-03-05T00:00:00Z | 1250 |
2020-03-15T00:00:00Z | 600 |
2020-02-15T00:00:00Z or from 2020-04-01T00:00:00ZAuthorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Response
Success response
Response to GetMetrics Request
Show child attributes
Show child attributes
โI
