Skip to main content

Installation


Quick Start

The Metrifox SDK supports a modern client-based architecture for better organization and type safety.

Configuration

Node.js:
Vite/React:
Alternative - Direct Initialization:
Get your API key from Settings → API Keys in your Metrifox dashboard.

Customer Management

Create a Customer

Update a Customer

The customer_key cannot be changed after creation.

Get Customer Data

Delete a Customer

Archive / Unarchive a Customer

Bulk CSV Upload


Usage Tracking & Access Control

Check Feature Access

Record Usage Events

List Usage Events

Retrieve usage events with optional filters and pagination:

Compute Quantity Price

Compute the price for a given quantity of a feature for a customer, based on their plan. Useful for previewing upgrade costs or showing customers the cost of additional usage before they commit.
Only available to tenants whose plan includes the finance API feature.

Complete Usage Example


Checkout & Billing

Embed Checkout Pages

Generate Checkout URL

Card Collection URL

Generate a hosted URL for collecting a payment method against an existing subscription or order. Useful for trial-to-paid conversions and re-collecting card details after expiry.

Wallets & Credit Allocations


Framework Integration

React/Vite

Setup in main.jsx:
Use in components:

Next.js

Setup in _app.js:

Express


API Reference

Client Architecture

Functions

Initialization:
  • init(config?) - Initialize and return the SDK client. config accepts apiKey, baseUrl, webAppBaseUrl, and meterServiceBaseUrl.
Usage Module (client.usages):
  • checkAccess(request) - Check feature access for a customer
  • recordUsage(request) - Record a usage event
  • listEvents(params?) - List recorded usage events with optional filters and pagination
  • quantityPrice(request) - Compute the price of a usage quantity (requires finance API feature)
Customers Module (client.customers):
  • create(request) - Add a customer
  • update(customerKey, request) - Update a customer
  • list(params?) - Get a paginated list of customers
  • get(customerKey) - Get a customer
  • delete(customerKey) - Delete a customer
  • archive(customerKey) - Archive a customer
  • unarchive(customerKey) - Restore an archived customer
  • getDetails(customerKey) - Get detailed customer information
  • uploadCsv(file) - Upload a CSV list of customers
  • bulkCreate(request) - Create multiple customers in one call
  • checkActiveSubscription(customerKey) - Check for active subscription
Checkout Module (client.checkout):
  • embed(config) - Embed checkout pages in your application
  • url(config) - Generate a checkout URL
  • cardCollectionUrl(config) - Generate a hosted card-collection URL
Wallets Module (client.wallets):
  • list(customerKey) - List a customer’s credit wallets
  • listCreditAllocations(walletId, options?) - List credit allocations for a wallet (optionally filtered by status)
  • getCreditAllocation(allocationId) - Get a single allocation with transaction history

TypeScript Support

All TypeScript types are available for import:

Error Handling


Configuration

Environment Variables

Node.js:
Vite:
Create React App:

Custom URLs

The meter service URL can also be overridden via the METRIFOX_METER_SERVICE_BASE_URL environment variable.

Default URLs

  • Production API: https://api.metrifox.com/api/v1/
  • Meter Service: https://api-meter.metrifox.com/
  • Web App: https://app.metrifox.com

Support

The JavaScript SDK works seamlessly across all modern JavaScript environments including Node.js, React, Next.js, Vue, and more.