@agentpaid/ap-node-client
v1.4.2
Published
Official Node.js SDK for the Paid API
Readme
AgentPaid Node.js SDK
Official Node.js SDK for the AgentPaid API.
Installation
npm install @agentpaid/ap-node-clientUsage
import { ApClient } from '@agentpaid/ap-node-client';
// Initialize the client
const client = new ApClient(
'YOUR_API_KEY',
'YOUR_API_URL' // Optional, defaults to production URL
);
// Example: Record usage
async function recordUsage() {
try {
client.recordUsage(
'agentId',
'customerId',
'eventName',
{ key: 'value' }
);
// Signals are automatically flushed:
// - Every 30 seconds
// - When the buffer reaches 100 events
// To manually flush:
await client.flush();
} catch (error) {
console.error('Error:', error);
}
}API Documentation
Orders
createOrder(data: CreateOrderRequest): Promise<Order>getOrder(orderId: string): Promise<Order>listOrders(): Promise<Order[]>addOrderLines(orderId: string, lines: CreateOrderLineRequest[]): Promise<OrderLine[]>activateOrder(orderId: string): Promise<string>deleteOrder(orderId: string): Promise<void>
Agents
createAgent(data: CreateAgentRequest): Promise<Agent>getAgent(agentId: string): Promise<Agent>getAgentByExternalId(externalId: string): Promise<Agent>listAgents(): Promise<Agent[]>updateAgent(agentId: string, data: UpdateAgentRequest): Promise<Agent>updateAgentByExternalId(externalId: string, data: UpdateAgentRequest): Promise<Agent>deleteAgent(agentId: string): Promise<void>deleteAgentByExternalId(externalId: string): Promise<void>
Accounts
createAccount(data: CreateAccountRequest): Promise<Account>getAccount(accountId: string): Promise<Account>getAccountByExternalId(externalId: string): Promise<Account>listAccounts(): Promise<Account[]>updateAccount(accountId: string, data: UpdateAccountRequest): Promise<Account>updateAccountByExternalId(externalId: string, data: UpdateAccountRequest): Promise<Account>deleteAccount(accountId: string): Promise<void>deleteAccountByExternalId(externalId: string): Promise<void>
Contacts
createContact(data: CreateContactRequest): Promise<Contact>getContact(contactId: string): Promise<Contact>getContactByExternalId(externalId: string): Promise<Contact>listContacts(externalId?: string): Promise<Contact[]>deleteContact(accountId?: string): Promise<void>deleteContactExternalId(externalId: string): Promise<Contact>
Usage Recording
recordUsage<T>(agentId: string, externalUserId: string, signalName: string, data: T): voidflush(): Promise<void>
