Getting Started
Amberflo SDKs

TypeScript and JavaScript

15min
https //github com/amberflo/metering typescript https //github com/amberflo/metering typescript import { ingestoptions, metering, flushmode, usageclient, usageapipayload, aggregationtype, aggregationinterval, timerange } from "amberflo metering typescript"; / this sample illustrates how to ingest your metering data into amberflo in auto flush mode auto is the default mode / export async function runingest() { //obtain your amberflo api key const apikey = 'my api key'; //optional ingest options let ingestoptions = new ingestoptions(); //set flush mode to auto this is also the default, so this step is optional ingestoptions flushmode = flushmode auto; //number of messages posted to the api default is 100 ingestoptions batchsize = 20; //frequency at which queued data will be sent to api default is 1000 milliseconds ingestoptions frequencymillis = 3000; //set to true to log debug statements const debug = false; const metering = new metering(apikey, debug, ingestoptions); //initialize and start the ingestion client metering start(); //define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); let j = 0; for (j = 0; j < 50; j++) { let delay = new promise(resolve => settimeout(resolve, 100)); await delay; //queue meter messages for ingestion //in auto flush mode, queue will be flushed when ingestoptions batchsize is exceeded or periodically ingestoptions frequencymillis //params meterapiname string, metervalue number, metertimeinmillis number, customerid string, dimensions map\<string, string> metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); metering meter("typescript bandwidth", j + 1, date now(), "123", dimensions); metering meter("typescript transactions", j + 1, date now(), "123", dimensions); metering meter("typescript cpu", j + 1, date now(), "123", dimensions); } //wait for messages and requests to api to complete await metering flush(); //perform graceful shutdown, flush, stop the timer await metering shutdown(); } runingest(); / this sample illustrates how to setup customer details / export async function runcustomerdetails() { //obtain your amberflo api key const apikey = 'my api key'; const traits = new map\<string, string>(); traits set("stripeid", "cus aj6by3vqcalaes"); traits set("customertype", "tech"); const metering = new metering(apikey, false); await metering addorupdatecustomerdetails('123', 'dell', traits); console log('customer setup completed!'); } runcustomerdetails(); export async function runusage() { //obtain your amberflo api key const apikey = 'my api key'; //initialize the usage client const client = new usageclient(apikey); // start date time represented as seconds since the unix epoch (1970 01 01t00 00 00z) and using utc // following is start time for last 24 hours const starttimeinseconds = math ceil(((new date() gettime()) (24 60 60 1000)) / 1000); let timerange = new timerange(); timerange starttimeinseconds = starttimeinseconds; // example 1 group by customers for a specific meter and all customers // setup usage query params // visit following link for description of payload // https //amberflo readme io/docs/getting started sample data#query the usage data let payload = new usageapipayload(); payload meterapiname = 'typescript apicalls'; payload aggregation = aggregationtype sum; payload timegroupinginterval = aggregationinterval day; //optional group the result by customer payload groupby = \["customerid"]; payload timerange = timerange; //call the usage api let jsonresult = await client getusage(payload); // to understand the api response, visit following link // https //amberflo readme io/docs/getting started sample data#query the usage data console log(json stringify(jsonresult, null, 4)); //example 2 filter for a meter for specific customer //setup usage query params let payloadforfilteredcustomer = new usageapipayload(); payloadforfilteredcustomer meterapiname = 'typescript apicalls'; payloadforfilteredcustomer aggregation = aggregationtype sum; payloadforfilteredcustomer timegroupinginterval = aggregationinterval day; //optional group the result by customer payloadforfilteredcustomer groupby = \["customerid"]; //filter result for a specific customer by id payloadforfilteredcustomer filter = {customerid \["123"]}; payloadforfilteredcustomer timerange = timerange; //call the usage api let jsonresultforfilteredcustomer = await client getusage(payloadforfilteredcustomer); console log(json stringify(jsonresultforfilteredcustomer, null, 4)); } runusage();{"success"\ true} import { ingestoptions, metering, flushmode, usageclient, usageapipayload, aggregationtype, aggregationinterval, timerange } from "amberflo metering typescript"; / this sample illustrates how to ingest your metering data into amberflo in auto flush mode auto is the default mode / export async function runingest() { //obtain your amberflo api key const apikey = 'my api key'; //optional ingest options let ingestoptions = new ingestoptions(); //set flush mode to auto this is also the default, so this step is optional ingestoptions flushmode = flushmode auto; //number of messages posted to the api default is 100 ingestoptions batchsize = 20; //frequency at which queued data will be sent to api default is 1000 milliseconds ingestoptions frequencymillis = 3000; //set to true to log debug statements const debug = false; const metering = new metering(apikey, debug, ingestoptions); //initialize and start the ingestion client metering start(); //define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); let j = 0; for (j = 0; j < 50; j++) { let delay = new promise(resolve => settimeout(resolve, 100)); await delay; //queue meter messages for ingestion //in auto flush mode, queue will be flushed when ingestoptions batchsize is exceeded or periodically ingestoptions frequencymillis //params meterapiname string, metervalue number, metertimeinmillis number, customerid string, dimensions map\<string, string> metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); metering meter("typescript bandwidth", j + 1, date now(), "123", dimensions); metering meter("typescript transactions", j + 1, date now(), "123", dimensions); metering meter("typescript cpu", j + 1, date now(), "123", dimensions); } //wait for messages and requests to api to complete await metering flush(); //perform graceful shutdown, flush, stop the timer await metering shutdown(); } runingest(); / this sample illustrates how to setup customer details / export async function runcustomerdetails() { //obtain your amberflo api key const apikey = 'my api key'; const traits = new map\<string, string>(); traits set("stripeid", "cus aj6by3vqcalaes"); traits set("customertype", "tech"); const metering = new metering(apikey, false); await metering addorupdatecustomerdetails('123', 'dell', traits); console log('customer setup completed!'); } runcustomerdetails(); export async function runusage() { //obtain your amberflo api key const apikey = 'my api key'; //initialize the usage client const client = new usageclient(apikey); // start date time represented as seconds since the unix epoch (1970 01 01t00 00 00z) and using utc // following is start time for last 24 hours const starttimeinseconds = math ceil(((new date() gettime()) (24 60 60 1000)) / 1000); let timerange = new timerange(); timerange starttimeinseconds = starttimeinseconds; // example 1 group by customers for a specific meter and all customers // setup usage query params // visit following link for description of payload // https //amberflo readme io/docs/getting started sample data#query the usage data let payload = new usageapipayload(); payload meterapiname = 'typescript apicalls'; payload aggregation = aggregationtype sum; payload timegroupinginterval = aggregationinterval day; //optional group the result by customer payload groupby = \["customerid"]; payload timerange = timerange; //call the usage api let jsonresult = await client getusage(payload); // to understand the api response, visit following link // https //amberflo readme io/docs/getting started sample data#query the usage data console log(json stringify(jsonresult, null, 4)); //example 2 filter for a meter for specific customer //setup usage query params let payloadforfilteredcustomer = new usageapipayload(); payloadforfilteredcustomer meterapiname = 'typescript apicalls'; payloadforfilteredcustomer aggregation = aggregationtype sum; payloadforfilteredcustomer timegroupinginterval = aggregationinterval day; //optional group the result by customer payloadforfilteredcustomer groupby = \["customerid"]; //filter result for a specific customer by id payloadforfilteredcustomer filter = {customerid \["123"]}; payloadforfilteredcustomer timerange = timerange; //call the usage api let jsonresultforfilteredcustomer = await client getusage(payloadforfilteredcustomer); console log(json stringify(jsonresultforfilteredcustomer, null, 4)); } runusage();{"success"\ true} import { ingestoptions, metering, flushmode, usageclient, usageapipayload, aggregationtype, aggregationinterval, timerange } from "amberflo metering typescript"; / this sample illustrates how to ingest your metering data into amberflo in auto flush mode auto is the default mode / export async function runingest() { //obtain your amberflo api key const apikey = 'my api key'; //optional ingest options let ingestoptions = new ingestoptions(); //set flush mode to auto this is also the default, so this step is optional ingestoptions flushmode = flushmode auto; //number of messages posted to the api default is 100 ingestoptions batchsize = 20; //frequency at which queued data will be sent to api default is 1000 milliseconds ingestoptions frequencymillis = 3000; //set to true to log debug statements const debug = false; const metering = new metering(apikey, debug, ingestoptions); //initialize and start the ingestion client metering start(); //define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); let j = 0; for (j = 0; j < 50; j++) { let delay = new promise(resolve => settimeout(resolve, 100)); await delay; //queue meter messages for ingestion //in auto flush mode, queue will be flushed when ingestoptions batchsize is exceeded or periodically ingestoptions frequencymillis //params meterapiname string, metervalue number, metertimeinmillis number, customerid string, dimensions map\<string, string> metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); metering meter("typescript bandwidth", j + 1, date now(), "123", dimensions); metering meter("typescript transactions", j + 1, date now(), "123", dimensions); metering meter("typescript cpu", j + 1, date now(), "123", dimensions); } //wait for messages and requests to api to complete await metering flush(); //perform graceful shutdown, flush, stop the timer await metering shutdown(); } runingest(); / this sample illustrates how to setup customer details / export async function runcustomerdetails() { //obtain your amberflo api key const apikey = 'my api key'; const traits = new map\<string, string>(); traits set("stripeid", "cus aj6by3vqcalaes"); traits set("customertype", "tech"); const metering = new metering(apikey, false); await metering addorupdatecustomerdetails('123', 'dell', traits); console log('customer setup completed!'); } runcustomerdetails(); export async function runusage() { //obtain your amberflo api key const apikey = 'my api key'; //initialize the usage client const client = new usageclient(apikey); // start date time represented as seconds since the unix epoch (1970 01 01t00 00 00z) and using utc // following is start time for last 24 hours const starttimeinseconds = math ceil(((new date() gettime()) (24 60 60 1000)) / 1000); let timerange = new timerange(); timerange starttimeinseconds = starttimeinseconds; // example 1 group by customers for a specific meter and all customers // setup usage query params // visit following link for description of payload // https //amberflo readme io/docs/getting started sample data#query the usage data let payload = new usageapipayload(); payload meterapiname = 'typescript apicalls'; payload aggregation = aggregationtype sum; payload timegroupinginterval = aggregationinterval day; //optional group the result by customer payload groupby = \["customerid"]; payload timerange = timerange; //call the usage api let jsonresult = await client getusage(payload); // to understand the api response, visit following link // https //amberflo readme io/docs/getting started sample data#query the usage data console log(json stringify(jsonresult, null, 4)); //example 2 filter for a meter for specific customer //setup usage query params let payloadforfilteredcustomer = new usageapipayload(); payloadforfilteredcustomer meterapiname = 'typescript apicalls'; payloadforfilteredcustomer aggregation = aggregationtype sum; payloadforfilteredcustomer timegroupinginterval = aggregationinterval day; //optional group the result by customer payloadforfilteredcustomer groupby = \["customerid"]; //filter result for a specific customer by id payloadforfilteredcustomer filter = {customerid \["123"]}; payloadforfilteredcustomer timerange = timerange; //call the usage api let jsonresultforfilteredcustomer = await client getusage(payloadforfilteredcustomer); console log(json stringify(jsonresultforfilteredcustomer, null, 4)); } runusage();{"success"\ true} import { ingestoptions, metering, flushmode, usageclient, usageapipayload, aggregationtype, aggregationinterval, timerange } from "amberflo metering typescript"; / this sample illustrates how to ingest your metering data into amberflo in auto flush mode auto is the default mode / export async function runingest() { //obtain your amberflo api key const apikey = 'my api key'; //optional ingest options let ingestoptions = new ingestoptions(); //set flush mode to auto this is also the default, so this step is optional ingestoptions flushmode = flushmode auto; //number of messages posted to the api default is 100 ingestoptions batchsize = 20; //frequency at which queued data will be sent to api default is 1000 milliseconds ingestoptions frequencymillis = 3000; //set to true to log debug statements const debug = false; const metering = new metering(apikey, debug, ingestoptions); //initialize and start the ingestion client metering start(); //define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); let j = 0; for (j = 0; j < 50; j++) { let delay = new promise(resolve => settimeout(resolve, 100)); await delay; //queue meter messages for ingestion //in auto flush mode, queue will be flushed when ingestoptions batchsize is exceeded or periodically ingestoptions frequencymillis //params meterapiname string, metervalue number, metertimeinmillis number, customerid string, dimensions map\<string, string> metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); metering meter("typescript bandwidth", j + 1, date now(), "123", dimensions); metering meter("typescript transactions", j + 1, date now(), "123", dimensions); metering meter("typescript cpu", j + 1, date now(), "123", dimensions); } //wait for messages and requests to api to complete await metering flush(); //perform graceful shutdown, flush, stop the timer await metering shutdown(); } runingest(); / this sample illustrates how to setup customer details / export async function runcustomerdetails() { //obtain your amberflo api key const apikey = 'my api key'; const traits = new map\<string, string>(); traits set("stripeid", "cus aj6by3vqcalaes"); traits set("customertype", "tech"); const metering = new metering(apikey, false); await metering addorupdatecustomerdetails('123', 'dell', traits); console log('customer setup completed!'); } runcustomerdetails(); export async function runusage() { //obtain your amberflo api key const apikey = 'my api key'; //initialize the usage client const client = new usageclient(apikey); // start date time represented as seconds since the unix epoch (1970 01 01t00 00 00z) and using utc // following is start time for last 24 hours const starttimeinseconds = math ceil(((new date() gettime()) (24 60 60 1000)) / 1000); let timerange = new timerange(); timerange starttimeinseconds = starttimeinseconds; // example 1 group by customers for a specific meter and all customers // setup usage query params // visit following link for description of payload // https //amberflo readme io/docs/getting started sample data#query the usage data let payload = new usageapipayload(); payload meterapiname = 'typescript apicalls'; payload aggregation = aggregationtype sum; payload timegroupinginterval = aggregationinterval day; //optional group the result by customer payload groupby = \["customerid"]; payload timerange = timerange; //call the usage api let jsonresult = await client getusage(payload); // to understand the api response, visit following link // https //amberflo readme io/docs/getting started sample data#query the usage data console log(json stringify(jsonresult, null, 4)); //example 2 filter for a meter for specific customer //setup usage query params let payloadforfilteredcustomer = new usageapipayload(); payloadforfilteredcustomer meterapiname = 'typescript apicalls'; payloadforfilteredcustomer aggregation = aggregationtype sum; payloadforfilteredcustomer timegroupinginterval = aggregationinterval day; //optional group the result by customer payloadforfilteredcustomer groupby = \["customerid"]; //filter result for a specific customer by id payloadforfilteredcustomer filter = {customerid \["123"]}; payloadforfilteredcustomer timerange = timerange; //call the usage api let jsonresultforfilteredcustomer = await client getusage(payloadforfilteredcustomer); console log(json stringify(jsonresultforfilteredcustomer, null, 4)); } runusage();{"success"\ true} import { ingestoptions, metering, flushmode, usageclient, usageapipayload, aggregationtype, aggregationinterval, timerange } from "amberflo metering typescript"; / this sample illustrates how to ingest your metering data into amberflo in auto flush mode auto is the default mode / export async function runingest() { //obtain your amberflo api key const apikey = 'my api key'; //optional ingest options let ingestoptions = new ingestoptions(); //set flush mode to auto this is also the default, so this step is optional ingestoptions flushmode = flushmode auto; //number of messages posted to the api default is 100 ingestoptions batchsize = 20; //frequency at which queued data will be sent to api default is 1000 milliseconds ingestoptions frequencymillis = 3000; //set to true to log debug statements const debug = false; const metering = new metering(apikey, debug, ingestoptions); //initialize and start the ingestion client metering start(); //define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); let j = 0; for (j = 0; j < 50; j++) { let delay = new promise(resolve => settimeout(resolve, 100)); await delay; //queue meter messages for ingestion //in auto flush mode, queue will be flushed when ingestoptions batchsize is exceeded or periodically ingestoptions frequencymillis //params meterapiname string, metervalue number, metertimeinmillis number, customerid string, dimensions map\<string, string> metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); metering meter("typescript bandwidth", j + 1, date now(), "123", dimensions); metering meter("typescript transactions", j + 1, date now(), "123", dimensions); metering meter("typescript cpu", j + 1, date now(), "123", dimensions); } //wait for messages and requests to api to complete await metering flush(); //perform graceful shutdown, flush, stop the timer await metering shutdown(); } runingest(); / this sample illustrates how to setup customer details / export async function runcustomerdetails() { //obtain your amberflo api key const apikey = 'my api key'; const traits = new map\<string, string>(); traits set("stripeid", "cus aj6by3vqcalaes"); traits set("customertype", "tech"); const metering = new metering(apikey, false); await metering addorupdatecustomerdetails('123', 'dell', traits); console log('customer setup completed!'); } runcustomerdetails(); export async function runusage() { //obtain your amberflo api key const apikey = 'my api key'; //initialize the usage client const client = new usageclient(apikey); // start date time represented as seconds since the unix epoch (1970 01 01t00 00 00z) and using utc // following is start time for last 24 hours const starttimeinseconds = math ceil(((new date() gettime()) (24 60 60 1000)) / 1000); let timerange = new timerange(); timerange starttimeinseconds = starttimeinseconds; // example 1 group by customers for a specific meter and all customers // setup usage query params // visit following link for description of payload // https //amberflo readme io/docs/getting started sample data#query the usage data let payload = new usageapipayload(); payload meterapiname = 'typescript apicalls'; payload aggregation = aggregationtype sum; payload timegroupinginterval = aggregationinterval day; //optional group the result by customer payload groupby = \["customerid"]; payload timerange = timerange; //call the usage api let jsonresult = await client getusage(payload); // to understand the api response, visit following link // https //amberflo readme io/docs/getting started sample data#query the usage data console log(json stringify(jsonresult, null, 4)); //example 2 filter for a meter for specific customer //setup usage query params let payloadforfilteredcustomer = new usageapipayload(); payloadforfilteredcustomer meterapiname = 'typescript apicalls'; payloadforfilteredcustomer aggregation = aggregationtype sum; payloadforfilteredcustomer timegroupinginterval = aggregationinterval day; //optional group the result by customer payloadforfilteredcustomer groupby = \["customerid"]; //filter result for a specific customer by id payloadforfilteredcustomer filter = {customerid \["123"]}; payloadforfilteredcustomer timerange = timerange; //call the usage api let jsonresultforfilteredcustomer = await client getusage(payloadforfilteredcustomer); console log(json stringify(jsonresultforfilteredcustomer, null, 4)); } runusage();{"success"\ true} import { ingestoptions, metering, flushmode, usageclient, usageapipayload, aggregationtype, aggregationinterval, timerange } from "amberflo metering typescript"; / this sample illustrates how to ingest your metering data into amberflo in auto flush mode auto is the default mode / export async function runingest() { //obtain your amberflo api key const apikey = 'my api key'; //optional ingest options let ingestoptions = new ingestoptions(); //set flush mode to auto this is also the default, so this step is optional ingestoptions flushmode = flushmode auto; //number of messages posted to the api default is 100 ingestoptions batchsize = 20; //frequency at which queued data will be sent to api default is 1000 milliseconds ingestoptions frequencymillis = 3000; //set to true to log debug statements const debug = false; const metering = new metering(apikey, debug, ingestoptions); //initialize and start the ingestion client metering start(); //define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); let j = 0; for (j = 0; j < 50; j++) { let delay = new promise(resolve => settimeout(resolve, 100)); await delay; //queue meter messages for ingestion //in auto flush mode, queue will be flushed when ingestoptions batchsize is exceeded or periodically ingestoptions frequencymillis //params meterapiname string, metervalue number, metertimeinmillis number, customerid string, dimensions map\<string, string> metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); metering meter("typescript bandwidth", j + 1, date now(), "123", dimensions); metering meter("typescript transactions", j + 1, date now(), "123", dimensions); metering meter("typescript cpu", j + 1, date now(), "123", dimensions); } //wait for messages and requests to api to complete await metering flush(); //perform graceful shutdown, flush, stop the timer await metering shutdown(); } runingest(); / this sample illustrates how to setup customer details / export async function runcustomerdetails() { //obtain your amberflo api key const apikey = 'my api key'; const traits = new map\<string, string>(); traits set("stripeid", "cus aj6by3vqcalaes"); traits set("customertype", "tech"); const metering = new metering(apikey, false); await metering addorupdatecustomerdetails('123', 'dell', traits); console log('customer setup completed!'); } runcustomerdetails(); export async function runusage() { //obtain your amberflo api key const apikey = 'my api key'; //initialize the usage client const client = new usageclient(apikey); // start date time represented as seconds since the unix epoch (1970 01 01t00 00 00z) and using utc // following is start time for last 24 hours const starttimeinseconds = math ceil(((new date() gettime()) (24 60 60 1000)) / 1000); let timerange = new timerange(); timerange starttimeinseconds = starttimeinseconds; // example 1 group by customers for a specific meter and all customers // setup usage query params // visit following link for description of payload // https //amberflo readme io/docs/getting started sample data#query the usage data let payload = new usageapipayload(); payload meterapiname = 'typescript apicalls'; payload aggregation = aggregationtype sum; payload timegroupinginterval = aggregationinterval day; //optional group the result by customer payload groupby = \["customerid"]; payload timerange = timerange; //call the usage api let jsonresult = await client getusage(payload); // to understand the api response, visit following link // https //amberflo readme io/docs/getting started sample data#query the usage data console log(json stringify(jsonresult, null, 4)); //example 2 filter for a meter for specific customer //setup usage query params let payloadforfilteredcustomer = new usageapipayload(); payloadforfilteredcustomer meterapiname = 'typescript apicalls'; payloadforfilteredcustomer aggregation = aggregationtype sum; payloadforfilteredcustomer timegroupinginterval = aggregationinterval day; //optional group the result by customer payloadforfilteredcustomer groupby = \["customerid"]; //filter result for a specific customer by id payloadforfilteredcustomer filter = {customerid \["123"]}; payloadforfilteredcustomer timerange = timerange; //call the usage api let jsonresultforfilteredcustomer = await client getusage(payloadforfilteredcustomer); console log(json stringify(jsonresultforfilteredcustomer, null, 4)); } runusage();{"success"\ true} amberflo https //amberflo io/ is the simplest way to integrate metering into your application this is the official typescript (and javascript) client that wraps the what is amberflo? docid\ fwibutraho4nvdb01lp4f features add and update customers assign and update product plans to customers list invoices of a customer get a new customer portal session for a customer add and list prepaid orders to customers send meter events in asynchronous batches for high throughput (with optional flush on demand) query usage quick start sign up for free https //ui amberflo io/ and get an api key install the sdk npm install save amberflo metering typescript 3\ create a customer import { customerdetailsclient, customerdetailsapipayload } from "amberflo metering typescript"; // 1 define some properties for this customer const customerid = '123'; const customername = 'dell'; const traits = new map\<string, string>(); traits set("customertype", "tech"); // 2 initialize metering client const client = new customerdetailsclient(apikey, debug); // 3 create or update the customer const payload = new customerdetailsapipayload(customerid, customername, traits); const createinstripe = true; const customer = await client add(payload, createinstripe); 4\ ingest meter events import { ingestoptions, metering, flushmode } from "amberflo metering typescript"; // 1 instantiate metering client const ingestoptions = new ingestoptions(); ingestoptions flushmode = flushmode auto; ingestoptions batchsize = 20; ingestoptions frequencymillis = 3000; const metering = new metering('my api key', false, ingestoptions); // 2 initialize and start the ingestion client metering start(); // optional define dimesions for your meters const dimensions = new map\<string, string>(); dimensions set("region", "midwest"); dimensions set("customertype", "tech"); // 3 queue meter messages for ingestion metering meter("typescript apicalls", j + 1, date now(), "123", dimensions); // 4 perform graceful shutdown, flush, stop the timer await metering shutdown(); 5\ query usage import { aggregationinterval, aggregationtype, timerange, usageapipayload, usageclient, } from "amberflo metering typescript"; // 1 initialize the usage client const client = new usageclient(apikey, debug); // 2 define a time range const starttimeinseconds = math ceil((new date() gettime() 24 60 60 1000) / 1000); // two days ago const timerange = new timerange(starttimeinseconds); // 3 get overall usage report of a meter const payload = new usageapipayload( 'typescript apicalls', aggregationtype sum, aggregationinterval day, timerange, ); const result = await client getusage(payload); with javascript this library can also be used directly with javascript for instance for instance, suppose you have the index js bellow you can run it with node index js 'use strict'; const apikey = 'my amberflo api key'; const { customerdetailsclient } = require('amberflo metering typescript'); async function main() { const client = new customerdetailsclient(apikey); const customers = await client list(); console log(customers); } main(); high throughput ingestion amberflo io libraries are built to support high throughput environments that means you can safely send hundreds of meter records per second for example, you can chose to deploy it on a web server that is serving hundreds of requests per second however, every call does not result in a http request, but is queued in memory instead messages are batched and flushed in the background, allowing for much faster operation the size of batch and rate of flush can be customized automatic flush when operating with auto flush mode, which is the default, the messages will accumulate in the queue until either the batch size is reached or some period of time elapses when either happens, the batch is sent flush on demand for example, at the end of your program, you'll want to flush to make sure there's nothing left in the queue calling this method will block the calling thread until there are no messages left in the queue so, you'll want to use it as part of your cleanup scripts and avoid using it as part of the request lifecycle documentation general documentation on how to use amberflo is available at onboarding walkthrough docid\ n7 owhejvrapwtrzb7mkb the full rest api documentation is available at getting started docid\ kdkc4ffc0 k 1anjm362f samples code samples covering different scenarios are available in the samples https //github com/amberflo/metering typescript/tree/master/samples folder reference api clients ingest meter records docid\ t8ybtn9tmllhzvbed2w2p import { ingestoptions, metering, flushmode } from "amberflo metering typescript"; create a customer docid\ iwtzya4jwllxbgp3qazsl import { customerdetailsclient, customerdetailsapipayload } from "amberflo metering typescript"; query the usage data docid\ smvdzw1fyu6jwyl5ufqrd import { aggregationinterval, aggregationtype, allusageapipayload, allusagegroupby, timerange, usageapipayload, usageclient, } from "amberflo metering typescript"; create a session docid 8wrigrkizlweihh9zldvd import { customerportalsessionclient, customerportalsessionapipayload } from "amberflo metering typescript" order a one time or a recurrence prepaid card by price docid 0mhimkgho6rpx6lefiwpf import { customerprepaidorderclient, customerprepaidorderapipayload, billingperiod, billingperiodinterval, } from "amberflo metering typescript"; get an invoice docid\ kovslccojef4x1qutnzv0 import { allinvoicesquery, latestinvoicequery, invoicequery, customerproductinvoiceclient, } from "amberflo metering typescript"; assign a product plan to a customer docid 0jdvdpttwte czaskhp n import { customerproductplanclient, customerproductplanapipayload, } from "amberflo metering typescript";