Create an usage meter
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",
"order": 1,
"computation": "1"
}
]
}
Usage Meters
Create an usage meter
Create an usage meter and associate with an event schema
POST
/
usage_meters
Create an usage meter
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",
"order": 1,
"computation": "1"
}
]
}
Authorizations
Body
application/json
Payload to create usage meter
Request to create usage meter
Response
Response for Create and Get usage event requests
Structure of usage meter
