Node SDK
A thin, typed wrapper over the REST API for Node 18 and up. One class, five resources, the same field names as the API.
Install
npm install @agentpay-global/sdkThe package is ESM and TypeScript-typed. It uses the global fetch (Node 18+); pass your own fetch in the options for older runtimes or custom agents.
Create a client
import { AgentPay } from "@agentpay-global/sdk";
const agentpay = new AgentPay(process.env.AGENTPAY_API_KEY);
// or
const agentpay = new AgentPay({ apiKey: process.env.AGENTPAY_API_KEY, baseUrl: "https://api.joomjoo.com" });Resources
Every method returns the parsed JSON of the matching endpoint. Field names are exactly the API's.
| Method | Endpoint |
|---|---|
cards.create(params) | POST /v1/cards |
cards.reveal(id) | GET /v1/cards/{id} |
cards.close(id) | POST /v1/cards/{id}/close |
spend.get(spendRequestId) | GET /v1/spend/{spend_request_id} |
checkout.create(params) | POST /v1/checkout |
checkout.get(checkoutId) | GET /v1/checkout/{checkout_id} |
connections.create(params) | POST /v1/connections |
connections.complete(id) | POST /v1/connections/{id}/complete |
connections.list() | GET /v1/connections |
connections.get(id) | GET /v1/connections/{id} |
wallet.get() | GET /v1/wallet |
wallet.createFundingSession(params) | POST /v1/wallet/funding-sessions |
wallet.declareBankTransfer(params) | POST /v1/wallet/bank-transfers |
Endpoints the SDK does not wrap yet (GET /v1/cards, POST /v1/cards/connect, DELETE /v1/cards/{id}, POST /v1/connections/{id}/passkey, DELETE /v1/connections/{id}) are one fetch away with the same bearer header.
Example
import { AgentPay, AgentPayError } from "@agentpay-global/sdk";
const agentpay = new AgentPay(process.env.AGENTPAY_API_KEY);
const run = await agentpay.checkout.create({
task: "buy the domain example.click for 1 year",
merchant: "namecheap",
amount: 20,
confirm_pay: true,
idempotency_key: "order-001",
});
const TERMINAL = new Set(["submitted", "canceled", "blocked", "error"]);
let status = run;
while (!TERMINAL.has(status.status)) {
await new Promise((r) => setTimeout(r, 8000));
status = await agentpay.checkout.get(run.checkout_id);
}
console.log(status.status, status.order_id, status.order_total);Errors
Any non-2xx response throws an AgentPayError with status, code (the API's error string), message and requestId.
try {
await agentpay.cards.create({ amount: 20, merchant: "namecheap" });
} catch (e) {
if (e instanceof AgentPayError) console.error(e.status, e.code, e.requestId);
}Types
Card, RevealedCard, ClosedCard, SpendStatus, Checkout, Connection, Wallet, FundingSession, BankTransfer and the Create...Params interfaces are exported. Checkout.status is the union of the ten checkout statuses.