Skip to main content
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"
          ]
        }
      ]
    }
  ]
}'
{
  "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
          ]
        }
      ]
    }
  ]
}

MetricQuery: Allowed field combinations

Metric NameConfig KeyAllowed ValuesDefault valueDescription
REVENUECURRENCYBASE or INVOICEBASEcurrency to return the revenue in
REVENUE_FOR_CYCLECURRENCYBASE or INVOICEBASEcurrency to return the revenue in
Metric NameFilterEntry NameAllowed groupBy fieldsDefault ValuesAllowed Values
EVENTSACCOUNT_IDACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME,None*<one or more valid account IDs>
EVENTSCUSTOMER_IDACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME,None*<one or more valid customer IDs>
EVENTSSCHEMA_NAMEACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME,None*<at most one valid schema names>
EVENTSEVENT_STATUSACCOUNT_ID, EVENT_STATUS, SCHEMA_NAME,[PROCESSED, UNPROCESSED]oneOrMoreOf PROCESSED, UNPROCESSED, IN_PROGRESS
USAGEACCOUNT_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid account IDs>
USAGECUSTOMER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid customer IDs>
USAGEUSAGE_METER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid usage meter name>
REVENUEACCOUNT_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid account IDs>
REVENUECUSTOMER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid customer IDs>
REVENUEUSAGE_METER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid usage meter name>
USAGE_FOR_CYCLEACCOUNT_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid account IDs>
USAGE_FOR_CYCLECUSTOMER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid customer IDs>
USAGE_FOR_CYCLEUSAGE_METER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid usage meter name>
REVENUE_FOR_CYCLEACCOUNT_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid account IDs>
REVENUE_FOR_CYCLECUSTOMER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid customer IDs>
REVENUE_FOR_CYCLEUSAGE_METER_IDACCOUNT_ID, USAGE_METER_ID, CUSTOMER_IDNone*<one or more valid usage meter name>

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.
PricingCycleStartDateUsage/RevenueForCycle
2020-01-05T00:00:00Z1000
2020-02-05T00:00:00Z1200
2020-03-05T00:00:00Z1200
In case of changes to the plan, e.g, a different monthly plan which is configured to invoice on 1st of every month is associated to account from 2020-03-15, metrics are stored as follows.
PricingCycleStartDateUsage/RevenueForCycle
2020-01-05T00:00:00Z1000
2020-02-05T00:00:00Z1200
2020-03-05T00:00:00Z1250
2020-03-15T00:00:00Z600
2020-04-01T00:00:00Z1300
2020-05-01T00:00:00Z1300

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.
PricingCycleStartDateUsage/RevenueForCycle
2020-03-05T00:00:00Z1250
2020-03-15T00:00:00Z600
and not data from 2020-02-15T00:00:00Z or from 2020-04-01T00:00:00Z

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Request to get metrics from togai

startTime
string<date-time>
required

Start date time of the query (inclusive)

Example:

"2017-07-21T00:00:00Z"

endTime
string<date-time>
required

End date time of the query (exclusive)

Example:

"2017-07-21T00:00:00Z"

metricQueries
object[]
required

Response

Success response

Response to GetMetrics Request

results
object[]
required
I