Skip to main content

API Examples (Node.js)

These examples use Node.js 18+ (built-in fetch, no extra packages needed). Copy the full script or individual functions into your project. Requirements:
  • Node.js 18+ (uses built-in fetch, no extra packages needed)
  • A valid Niftipay API key (generate one in Dashboard → Settings)

Configuration


Helper: make an authenticated request

All examples below use this shared helper to make authenticated API calls:

Example 1: Create a Crypto Invoice Order

This creates a crypto payment invoice that your customer can pay directly from their wallet. Once the on-chain payment is detected, the order is marked “paid” and a webhook fires. Endpoint: POST /api/orders Flow:
  1. You call POST /api/orders with customer + amount details
  2. The API returns a deposit address, payment URI, and QR code
  3. You show the QR / URI to your customer
  4. Customer sends crypto to the deposit address
  5. Order status changes to “paid” → webhook fires
See also: Crypto Orders API reference

This creates a hosted checkout link where your customer can buy crypto with a credit card or bank transfer. The purchased crypto is sent to a Niftipay deposit address, and once detected on-chain, you receive the funds and a webhook fires. Endpoint: POST /api/ramping/links Flow:
  1. You call POST /api/ramping/links with customer + fiat amount
  2. The API returns a redirect URL (hosted checkout page)
  3. You redirect the customer to that URL
  4. Customer picks a payment method (card / bank), completes KYC if needed
  5. Provider purchases crypto and sends it to the deposit address
  6. Once on-chain deposit is detected, order is marked “paid” → webhook fires
See also: Onramping API reference

Example 3: Create a Fiat Payment Order

This creates a fiat payment order (card / bank transfer) using one of your configured fiat integrations. The API returns a hosted payment URL where the customer completes the payment. Endpoint: POST /api/fiat/orders Prerequisites:
  • Fiat payments must be enabled on your account
  • You need a fiat Integration ID (find it in Dashboard → Settings → Fiat)
Flow:
  1. You call POST /api/fiat/orders with integration, amount, and currency
  2. The API returns a payment URL and QR code
  3. You redirect the customer to the payment URL (or show the QR code)
  4. Customer pays via card or bank transfer on the hosted page
  5. Order status changes to “completed” → webhook fires
See also: Fiat Orders API reference

Run all examples

To run:
  1. Replace YOUR_API_KEY and https://your-domain.com with your real values
  2. Save the full script as api-examples.mjs
  3. Run: node api-examples.mjs