API Guidelines
This page describes the recommended way to consume the Niftipay API across server integrations, dashboards, and embedded widgets. It covers:- Authentication methods
- Required/request headers
- Rate limits and
429handling - CORS rules and allowed origins
- Common response & error patterns
- Integration best practices (timeouts, retries, idempotency, pagination)
Base URL
All examples use:https://www.niftipay.com
Authentication
You can authenticate using either:1) API Key (recommended for integrations)
Send your API key in thex-api-key header:
2) Session cookie (dashboard / browser)
If you are authenticated in the dashboard, requests are auhtorized..If you’re building a backend integration (WooCommerce plugin, external servers, POS systems), use API keys.
Standard headers
Request headers
Common headers you may send:Accept: application/jsonContent-Type: application/json(for JSON bodies)x-api-key: ...(API key auth)Idempotency-Key: ...orx-idempotency-key: ...(when supported by an endpoint)x-publishable-key: ...(for embeddable ramping widget flows)
Not all endpoints use all headers; only send what the endpoint requires.
CORS allowlist headers
The proxy middleware allows these request headers for CORS:Content-TypeAuthorizationx-api-keyx-publishable-keyx-public-keyx-timestampx-signature
Rate limits
Niftipay applies rate limiting at multiple layers.1) Proxy-level enforcement for /api/*
All API routes are rate-limited by the proxy middleware:
If you exceed a limit, you’ll receive:
429 Too Many Requests
429 handling (recommended)
When you receive a429:
- Back off (exponential backoff recommended)
- Retry after a delay
- Avoid parallel bursts; queue requests
- wait 1s → 2s → 4s → 8s (cap at 30s)
- retry up to 3–5 times max (depending on endpoint criticality)
If you have high-volume needs, consolidate requests, cache responses, and avoid polling.
Request/response conventions
JSON responses
Most endpoints return JSON and use standard HTTP codes:200OK201Created204No Content (delete success)400Bad Request (invalid payload / missing params)401Unauthorized403Forbidden (method disabled, not allowed, failed guards)404Not Found409Conflict (duplicate reference, unsafe delete, etc.)429Too Many Requests500Internal Error502Upstream Error (provider/PSP failure)
Error shape
Most error responses are shaped like:Treaterroras display-safe text. Treatdetailsas diagnostic.
Pagination guidelines
Several list endpoints use cursor pagination (recommended for stable ordering). Example (fiat orders):- Response includes
nextCursor - Pass it back as
?cursor=<nextCursor>to fetch older rows
- Keep
limitbetween 20–50 - Do not request
limit > 100(clamped server-side)
Idempotency and safe retries
Some endpoints support idempotent behavior when you provide a stable identifier (likereference) and/or an idempotency header.
Recommended approach:
- Generate a stable reference for your business object (e.g. POS receipt number, WooCommerce order id).
- Send it consistently on create calls.
- If you must retry, reuse:
- the same
reference, and when supported - the same
Idempotency-Key
- the same
- the client times out
- the network drops
- you retry after transient errors
Timeouts & retries
Recommended timeouts
- Client timeout: 10–20 seconds (PSP and blockchain calls can take longer, but order creation typically should not hang)
- Webhook receivers: respond in < 2 seconds (providers often retry if slow)
Retry guidance
Safe to retry:GETrequestsDELETEthat is explicitly idempotent (returns same state if already deleted/cancelled)POSTonly if you have idempotency (reference/idempotency key) and the endpoint supports it
- payment creation without idempotency protection
- refunds, cancellations, or wallet operations unless the endpoint is designed to be idempotent
Webhooks and signatures
Niftipay supports webhooks for order state changes and refunds. Best practices for webhook receivers:- Always verify signatures (if enabled for your webhook)
- Respond quickly with
200 - Treat events as at-least-once delivery:
- you may receive duplicates
- you must dedupe using event id / order reference / order id
If you are using the default platform webhook (/api/niftipay/webhook on your domain), keep it publicly reachable and stable.
Troubleshooting checklist
Getting 401 Unauthorized
- Missing/invalid
x-api-key - Using a browser without a valid session cookie
Getting 403 Forbidden
- Payment method category disabled (e.g. fiat/crypto not enabled)
- Test/protected or guarded route requirements not met
- CORS preflight rejected due to origin rules
Getting 429 Too Many Requests
- Slow down and retry with backoff
- Avoid request bursts
- Cache responses where possible
Getting 502 Upstream Error
- Provider/PSP failed (e.g. NoPayn/Tatum)
- Retry only if safe and idempotent (see above)
- Log
detailsfor debugging
Example: minimal integration flow
- Fetch payment methods:
-
Create a crypto or fiat order (depending on
enabledmethods) - Listen for webhook events (paid/cancelled/refunded) and update your system