The Vayu API client library in TypeScript allows you to submit events for processing and storage, manage billing-related entities, and perform various other operations seamlessly.
Install the Vayu API client library using npm:
npm install vayu-client
Initialize the Vayu API client. The baseUrl
parameter is optional and defaults to Vayu's public API servers.
import { VayuClient } from 'vayu-client';
const vayu = new VayuClient({
accessToken: 'your-access-token',
baseUrl: 'https://connect.withvayu.com' // Optional
});
To obtain a new access token, use the login method:
const response = await vayu.auth.login({
refreshToken: 'your-refresh-token'
});
console.log(response.accessToken);
To send a batch of events for processing and storage:
const events = [
{
name: 'api_call', // The distinctive label assigned to an event
timestamp: new Date().toISOString(), // The exact moment of event occurrence in ISO 8601 format
customerAlias: 'customer_12345', // A unique identifier assigned to each customer
ref: '4f6cf35x-2c4y-483z-a0a9-158621f77a21', // A universally unique identifier for each event
data: {
key1: 'processing_duration', // Example additional data
key2: 'api_url' // Example additional data
}
}
];
const response = await vayu.events.sendEvents({ events });
console.log(response.validEvents);
console.log(response.invalidEvents);
To fetch events occurring within a specified timestamp range:
const response = await vayu.events.queryEvents({
startTime: '2023-09-01T00:00:00.000Z',
endTime: '2023-09-30T23:59:59.999Z',
eventName: 'api_call',
limit: 10
});
console.log(response.events);
To get a specific event using its reference ID:
const response = await vayu.events.getEventByRefId('4f6cf35x-2c4y-483z-a0a9-158621f77a21');
console.log(response.event);
To delete a specific event using its reference ID:
const response = await vayu.events.deleteEventByRefId('4f6cf35x-2c4y-483z-a0a9-158621f77a21');
console.log(response.event);
To create a new customer:
const response = await vayu.customers.createCustomer({
name: 'John Doe',
alias: 'customer_12345'
});
console.log(response.customer);
To update an existing customer by ID:
const response = await vayu.customers.updateCustomer('customer-id', {
name: 'Jane Doe',
alias: 'customer_67890'
});
console.log(response.customer);
To delete a customer by ID:
const response = await vayu.customers.deleteCustomer('customer-id');
console.log(response.customer);
Meters are entities that track and aggregate usage data based on events. They are crucial for billing and monitoring purposes.
To get a list of meters:
const response = await vayu.meters.listMeters({
limit: 10,
cursor: 'next-cursor'
});
console.log(response.meters);
console.log(response.total);
console.log(response.hasMore);
console.log(response.nextCursor);
The Vayu API client library provides access to the following features:
-
Auth
auth.login()
-
Events
events.sendEvents()
events.queryEvents()
events.getEventByRefId()
events.deleteEventByRefId()
events.sendEventsDryRun()
-
Customers
customers.createCustomer()
customers.updateCustomer()
customers.deleteCustomer()
customers.listCustomers()
customers.getCustomer()
-
Meters
meters.getMeter()
meters.updateMeter()
meters.deleteMeter()
meters.listMeters()
-
Plans
plans.getPlan()
plans.deletePlan()
plans.listPlans()
-
Contracts
contracts.createContract()
contracts.deleteContract()
contracts.listContracts()
contracts.getContract()
-
Invoices
invoices.getInvoice()
invoices.listInvoices()
If you have any questions or need further assistance, please contact Vayu at team@withvayu.com
.
This project is licensed under the MIT License.
This README provides an overview and usage examples for the Vayu API client library. For more detailed information on each method, please refer to the official Vayu API documentation.