curl --request POST \
--url https://api.togai.com/usage_meters \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Rides",
"description": "Cab rides",
"type": "COUNTER",
"aggregation": "SUM",
"eventSchemaName": "evfhr123d",
"computations": [
{
"matcher": "{\n \"and\": [\n {\"in\": [{\"var\": \"dimension.city\"}, \"chennai\", \"mumbai\"]},\n \"or\": [\n {\">\": [{\"var\": \"attribute.distance\"}, 100]},\n {\"<\": [{\"var\": \"attribute.distance\"}, 20]}\n ]\n ]\n}\n",
"computation": {
"*": [
{
"var": "attributes.distance"
},
0.4
]
}
}
]
}
'import requests
url = "https://api.togai.com/usage_meters"
payload = {
"name": "Rides",
"description": "Cab rides",
"type": "COUNTER",
"aggregation": "SUM",
"eventSchemaName": "evfhr123d",
"computations": [
{
"matcher": "{
\"and\": [
{\"in\": [{\"var\": \"dimension.city\"}, \"chennai\", \"mumbai\"]},
\"or\": [
{\">\": [{\"var\": \"attribute.distance\"}, 100]},
{\"<\": [{\"var\": \"attribute.distance\"}, 20]}
]
]
}
",
"computation": { "*": [{ "var": "attributes.distance" }, 0.4] }
}
]
}
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({
name: 'Rides',
description: 'Cab rides',
type: 'COUNTER',
aggregation: 'SUM',
eventSchemaName: 'evfhr123d',
computations: [
{
matcher: '{\n "and": [\n {"in": [{"var": "dimension.city"}, "chennai", "mumbai"]},\n "or": [\n {">": [{"var": "attribute.distance"}, 100]},\n {"<": [{"var": "attribute.distance"}, 20]}\n ]\n ]\n}\n',
computation: {'*': [{var: 'attributes.distance'}, 0.4]}
}
]
})
};
fetch('https://api.togai.com/usage_meters', 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/usage_meters",
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([
'name' => 'Rides',
'description' => 'Cab rides',
'type' => 'COUNTER',
'aggregation' => 'SUM',
'eventSchemaName' => 'evfhr123d',
'computations' => [
[
'matcher' => '{
"and": [
{"in": [{"var": "dimension.city"}, "chennai", "mumbai"]},
"or": [
{">": [{"var": "attribute.distance"}, 100]},
{"<": [{"var": "attribute.distance"}, 20]}
]
]
}
',
'computation' => [
'*' => [
[
'var' => 'attributes.distance'
],
0.4
]
]
]
]
]),
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/usage_meters"
payload := strings.NewReader("{\n \"name\": \"Rides\",\n \"description\": \"Cab rides\",\n \"type\": \"COUNTER\",\n \"aggregation\": \"SUM\",\n \"eventSchemaName\": \"evfhr123d\",\n \"computations\": [\n {\n \"matcher\": \"{\\n \\\"and\\\": [\\n {\\\"in\\\": [{\\\"var\\\": \\\"dimension.city\\\"}, \\\"chennai\\\", \\\"mumbai\\\"]},\\n \\\"or\\\": [\\n {\\\">\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 100]},\\n {\\\"<\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 20]}\\n ]\\n ]\\n}\\n\",\n \"computation\": {\n \"*\": [\n {\n \"var\": \"attributes.distance\"\n },\n 0.4\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/usage_meters")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Rides\",\n \"description\": \"Cab rides\",\n \"type\": \"COUNTER\",\n \"aggregation\": \"SUM\",\n \"eventSchemaName\": \"evfhr123d\",\n \"computations\": [\n {\n \"matcher\": \"{\\n \\\"and\\\": [\\n {\\\"in\\\": [{\\\"var\\\": \\\"dimension.city\\\"}, \\\"chennai\\\", \\\"mumbai\\\"]},\\n \\\"or\\\": [\\n {\\\">\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 100]},\\n {\\\"<\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 20]}\\n ]\\n ]\\n}\\n\",\n \"computation\": {\n \"*\": [\n {\n \"var\": \"attributes.distance\"\n },\n 0.4\n ]\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.togai.com/usage_meters")
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 \"name\": \"Rides\",\n \"description\": \"Cab rides\",\n \"type\": \"COUNTER\",\n \"aggregation\": \"SUM\",\n \"eventSchemaName\": \"evfhr123d\",\n \"computations\": [\n {\n \"matcher\": \"{\\n \\\"and\\\": [\\n {\\\"in\\\": [{\\\"var\\\": \\\"dimension.city\\\"}, \\\"chennai\\\", \\\"mumbai\\\"]},\\n \\\"or\\\": [\\n {\\\">\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 100]},\\n {\\\"<\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 20]}\\n ]\\n ]\\n}\\n\",\n \"computation\": {\n \"*\": [\n {\n \"var\": \"attributes.distance\"\n },\n 0.4\n ]\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "um.1zlQTBWlkeO.lB7fh",
"name": "Rides",
"displayName": "Rides",
"description": "Cab rides",
"type": "COUNTER",
"aggregation": "COUNT",
"status": "DRAFT",
"computations": [
{
"matcher": "{\n \"and\": [\n {\"in\": [{\"var\": \"dimension.city\"}, \"chennai\", \"mumbai\"]},\n \"or\": [\n {\">\": [{\"var\": \"attribute.distance\"}, 100]},\n {\"<\": [{\"var\": \"attribute.distance\"}, 20]}\n ]\n ]\n}\n",
"computation": "1"
}
]
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}Create an usage meter
Create an usage meter and associate with an event schema
curl --request POST \
--url https://api.togai.com/usage_meters \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"name": "Rides",
"description": "Cab rides",
"type": "COUNTER",
"aggregation": "SUM",
"eventSchemaName": "evfhr123d",
"computations": [
{
"matcher": "{\n \"and\": [\n {\"in\": [{\"var\": \"dimension.city\"}, \"chennai\", \"mumbai\"]},\n \"or\": [\n {\">\": [{\"var\": \"attribute.distance\"}, 100]},\n {\"<\": [{\"var\": \"attribute.distance\"}, 20]}\n ]\n ]\n}\n",
"computation": {
"*": [
{
"var": "attributes.distance"
},
0.4
]
}
}
]
}
'import requests
url = "https://api.togai.com/usage_meters"
payload = {
"name": "Rides",
"description": "Cab rides",
"type": "COUNTER",
"aggregation": "SUM",
"eventSchemaName": "evfhr123d",
"computations": [
{
"matcher": "{
\"and\": [
{\"in\": [{\"var\": \"dimension.city\"}, \"chennai\", \"mumbai\"]},
\"or\": [
{\">\": [{\"var\": \"attribute.distance\"}, 100]},
{\"<\": [{\"var\": \"attribute.distance\"}, 20]}
]
]
}
",
"computation": { "*": [{ "var": "attributes.distance" }, 0.4] }
}
]
}
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({
name: 'Rides',
description: 'Cab rides',
type: 'COUNTER',
aggregation: 'SUM',
eventSchemaName: 'evfhr123d',
computations: [
{
matcher: '{\n "and": [\n {"in": [{"var": "dimension.city"}, "chennai", "mumbai"]},\n "or": [\n {">": [{"var": "attribute.distance"}, 100]},\n {"<": [{"var": "attribute.distance"}, 20]}\n ]\n ]\n}\n',
computation: {'*': [{var: 'attributes.distance'}, 0.4]}
}
]
})
};
fetch('https://api.togai.com/usage_meters', 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/usage_meters",
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([
'name' => 'Rides',
'description' => 'Cab rides',
'type' => 'COUNTER',
'aggregation' => 'SUM',
'eventSchemaName' => 'evfhr123d',
'computations' => [
[
'matcher' => '{
"and": [
{"in": [{"var": "dimension.city"}, "chennai", "mumbai"]},
"or": [
{">": [{"var": "attribute.distance"}, 100]},
{"<": [{"var": "attribute.distance"}, 20]}
]
]
}
',
'computation' => [
'*' => [
[
'var' => 'attributes.distance'
],
0.4
]
]
]
]
]),
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/usage_meters"
payload := strings.NewReader("{\n \"name\": \"Rides\",\n \"description\": \"Cab rides\",\n \"type\": \"COUNTER\",\n \"aggregation\": \"SUM\",\n \"eventSchemaName\": \"evfhr123d\",\n \"computations\": [\n {\n \"matcher\": \"{\\n \\\"and\\\": [\\n {\\\"in\\\": [{\\\"var\\\": \\\"dimension.city\\\"}, \\\"chennai\\\", \\\"mumbai\\\"]},\\n \\\"or\\\": [\\n {\\\">\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 100]},\\n {\\\"<\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 20]}\\n ]\\n ]\\n}\\n\",\n \"computation\": {\n \"*\": [\n {\n \"var\": \"attributes.distance\"\n },\n 0.4\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/usage_meters")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Rides\",\n \"description\": \"Cab rides\",\n \"type\": \"COUNTER\",\n \"aggregation\": \"SUM\",\n \"eventSchemaName\": \"evfhr123d\",\n \"computations\": [\n {\n \"matcher\": \"{\\n \\\"and\\\": [\\n {\\\"in\\\": [{\\\"var\\\": \\\"dimension.city\\\"}, \\\"chennai\\\", \\\"mumbai\\\"]},\\n \\\"or\\\": [\\n {\\\">\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 100]},\\n {\\\"<\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 20]}\\n ]\\n ]\\n}\\n\",\n \"computation\": {\n \"*\": [\n {\n \"var\": \"attributes.distance\"\n },\n 0.4\n ]\n }\n }\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.togai.com/usage_meters")
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 \"name\": \"Rides\",\n \"description\": \"Cab rides\",\n \"type\": \"COUNTER\",\n \"aggregation\": \"SUM\",\n \"eventSchemaName\": \"evfhr123d\",\n \"computations\": [\n {\n \"matcher\": \"{\\n \\\"and\\\": [\\n {\\\"in\\\": [{\\\"var\\\": \\\"dimension.city\\\"}, \\\"chennai\\\", \\\"mumbai\\\"]},\\n \\\"or\\\": [\\n {\\\">\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 100]},\\n {\\\"<\\\": [{\\\"var\\\": \\\"attribute.distance\\\"}, 20]}\\n ]\\n ]\\n}\\n\",\n \"computation\": {\n \"*\": [\n {\n \"var\": \"attributes.distance\"\n },\n 0.4\n ]\n }\n }\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "um.1zlQTBWlkeO.lB7fh",
"name": "Rides",
"displayName": "Rides",
"description": "Cab rides",
"type": "COUNTER",
"aggregation": "COUNT",
"status": "DRAFT",
"computations": [
{
"matcher": "{\n \"and\": [\n {\"in\": [{\"var\": \"dimension.city\"}, \"chennai\", \"mumbai\"]},\n \"or\": [\n {\">\": [{\"var\": \"attribute.distance\"}, 100]},\n {\"<\": [{\"var\": \"attribute.distance\"}, 20]}\n ]\n ]\n}\n",
"computation": "1"
}
]
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}{
"message": "<Reason message>"
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Payload to create usage meter
Request to create usage meter
Name of the usage meter. Must be unique for an organization.
50^[\sa-zA-Z0-9_-]*$Type of usage meter
COUNTER Aggregation to be applied on usage meter result
COUNT, SUM Event Schema Identifier
Billable name of usage meter. Billable name takes precedence over name to display in invoice.
255Description of the usage meter
255Show child attributes
Show child attributes
Response
Response for Create and Get usage event requests
Structure of usage meter
Identifier of the usage meter
20Name of the usage meter
50^[\sa-zA-Z0-9_-]*$"rides-usage"
Display name of usage meter. This is an auto-generated field which contains billableName of usage meter. If billableName is not provided, name will be used as display name.
255Type of usage meter
COUNTER "COUNTER"
Aggregation to be applied on usage meter result
COUNT, SUM Billable name of addon. Billable name takes precedence over name to display in invoice.
255"Rides Usage"
255"Meter to track cab rides"
Status of usage meter
DRAFT, ACTIVE, INACTIVE, ARCHIVED "DRAFT"
1Show child attributes
Show child attributes
