# Error Handling Source: https://docs.nowramp.com/api/errors API error codes and handling # Error Handling The API uses standard HTTP status codes and returns detailed error information in the response body. ## HTTP Status Codes | Code | Description | | ----- | ----------------------------------------------------------- | | `200` | Success | | `201` | Created | | `400` | Bad Request - Invalid parameters | | `401` | Unauthorized - Invalid or missing API key | | `403` | Forbidden - Insufficient permissions | | `404` | Not Found - Resource doesn't exist | | `409` | Conflict - Duplicate idempotency key with different payload | | `422` | Unprocessable Entity - Validation failed | | `429` | Too Many Requests - Rate limit exceeded | | `500` | Internal Server Error | ## Error Response Format ```json theme={null} { "success": false, "error": { "code": "ERROR_CODE", "message": "Human-readable error message", "details": [ { "field": "fieldName", "message": "Field-specific error" } ], "requestId": "req_abc123" } } ``` ## Common Error Codes ### Validation Errors | Code | Description | | ------------------------ | ------------------------------------ | | `VALIDATION_ERROR` | Request parameters failed validation | | `INVALID_CURRENCY` | Unsupported currency code | | `INVALID_AMOUNT` | Amount is out of allowed range | | `INVALID_WALLET_ADDRESS` | Wallet address format is invalid | | `INVALID_NETWORK` | Unsupported network | | `INVALID_GATEWAY` | Gateway ID not found or not enabled | ### Resource Errors | Code | Description | | ----------------------- | ----------------------------------------- | | `TRANSACTION_NOT_FOUND` | Transaction ID doesn't exist | | `PROJECT_NOT_FOUND` | Project ID doesn't exist | | `GATEWAY_UNAVAILABLE` | Selected gateway is currently unavailable | ### Rate Limiting | Code | Description | | --------------------- | --------------------------------------------------------- | | `RATE_LIMIT_EXCEEDED` | Too many requests — include a `pk_` key for higher limits | ### Authentication Errors | Code | Description | | ----------------- | --------------------------------- | | `INVALID_API_KEY` | The API key is invalid or revoked | ## Handling Errors ### JavaScript Example ```javascript theme={null} async function getQuotes(params) { const response = await fetch( `https://api.nowramp.com/public/v1/onramp/quotes?${new URLSearchParams(params)}` ); const data = await response.json(); if (!data.success) { switch (data.error.code) { case 'VALIDATION_ERROR': // Show field-specific errors to the user console.error('Validation:', data.error.details); break; case 'INVALID_AMOUNT': // Amount is below minimum or above maximum console.error('Invalid amount:', data.error.message); break; case 'RATE_LIMIT_EXCEEDED': // Back off and retry await new Promise(r => setTimeout(r, 5000)); return getQuotes(params); default: throw new Error(data.error.message); } } return data.data; } ``` ## Retry Strategy For transient errors (5xx, network issues), implement exponential backoff: ```javascript theme={null} async function fetchWithRetry(url, options, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { const response = await fetch(url, options); if (response.status >= 500) { throw new Error('Server error'); } return response; } catch (error) { if (i === maxRetries - 1) throw error; const delay = Math.pow(2, i) * 1000; // 1s, 2s, 4s await new Promise(resolve => setTimeout(resolve, delay)); } } } ``` Always include the `requestId` from error responses when contacting support. # Onramp API Source: https://docs.nowramp.com/api/onramp Multi-provider aggregation endpoints for comparing quotes and processing purchases across payment gateways. # Onramp API The Onramp API provides multi-provider aggregation for crypto purchases. It fans out requests to all enabled payment gateways, compares quotes, and lets users checkout with their preferred provider. All endpoints are public and require a `projectId` parameter. No API key is needed. ## How It Works ```mermaid theme={null} sequenceDiagram participant App as Your App participant API as NowRamp API participant G1 as Gateway A participant G2 as Gateway B App->>API: GET /onramp/supported API-->>App: Providers, currencies, payment methods App->>API: GET /onramp/quotes API->>G1: Get quote API->>G2: Get quote G1-->>API: Quote G2-->>API: Quote API-->>App: Ranked quotes (best rate, cheapest, fastest) App->>API: POST /onramp/checkout-intent API->>G1: Create order G1-->>API: Checkout URL API-->>App: Checkout intent (iframe/redirect URL) App->>API: GET /onramp/transactions/:id API-->>App: Transaction status ``` ## Base URL ``` GET|POST /public/v1/onramp/* ``` *** ## Get Supported Configuration Returns available providers, fiat currencies, crypto currencies, payment methods, and countries aggregated across all enabled providers. ``` GET /public/v1/onramp/supported ``` ### Query Parameters | Parameter | Type | Required | Description | | ----------- | ------------- | -------- | ------------------------------------------------------------------------------- | | `projectId` | string (UUID) | Yes | Your project ID | | `orderType` | string | No | `buy` or `sell` (default: `buy`) | | `country` | string | No | ISO 2-letter country code (e.g., `US`, `GB`). Auto-detected from IP if omitted. | ### Response ```json theme={null} { "success": true, "data": { "providers": [ { "id": "provider_a", "name": "Provider A", "logo": "https://...", "enabled": true, "features": { "supportsIframe": true, "supportsWidget": false, "supportsBuy": true, "supportsSell": true, "supportsRecurring": false, "kycHandledByProvider": true } }, { "id": "provider_b", "name": "Provider B", "logo": "https://...", "enabled": true, "features": { "supportsIframe": false, "supportsWidget": true, "supportsBuy": true, "supportsSell": false, "supportsRecurring": false, "kycHandledByProvider": true } } ], "fiats": [ { "code": "USD", "name": "US Dollar", "symbol": "$", "minAmount": "30", "maxAmount": "15000", "providers": ["provider_a", "provider_b"], "paymentMethods": ["debit-credit-card", "apple-pay"] } ], "cryptos": [ { "code": "ETH", "name": "Ethereum", "networks": [ { "id": "ethereum", "name": "Ethereum", "minAmount": "0.001", "maxAmount": "999999", "providers": ["provider_a", "provider_b"] }, { "id": "polygon", "name": "Polygon", "minAmount": "0.01", "maxAmount": "999999", "providers": ["provider_a"] } ], "providers": ["provider_a", "provider_b"] } ], "paymentMethods": [ { "id": "debit-credit-card", "name": "Debit credit card", "description": null, "supportedFiats": ["USD", "EUR", "GBP"], "providers": ["provider_a"] } ], "countries": [ { "code": "US", "name": "United States", "providers": ["provider_a"] } ], "defaultGateway": "provider_a", "detectedCountry": "US" } } ``` ### Provider Features | Feature | Description | | ---------------------- | -------------------------------------------------- | | `supportsIframe` | Provider checkout can be embedded in an iframe | | `supportsWidget` | Provider provides a JavaScript widget for checkout | | `supportsBuy` | Supports fiat-to-crypto (on-ramp) | | `supportsSell` | Supports crypto-to-fiat (off-ramp) | | `supportsRecurring` | Supports recurring/subscription purchases | | `kycHandledByProvider` | Provider handles identity verification internally | *** ## Get Quotes Fetches quotes from all enabled gateways in parallel and returns them ranked by best rate. ``` GET /public/v1/onramp/quotes ``` ### Query Parameters | Parameter | Type | Required | Description | | ----------------- | ------------- | ------------ | ------------------------------------------------------------ | | `projectId` | string (UUID) | Yes | Your project ID | | `fiatCurrency` | string | Yes | Fiat currency code (e.g., `USD`) | | `cryptoCurrency` | string | Yes | Crypto currency code (e.g., `ETH`) | | `network` | string | Yes | Network ID (e.g., `ethereum`) | | `fiatAmount` | string | One required | Fiat amount (e.g., `100`). Required for buy orders. | | `cryptoAmount` | string | One required | Crypto amount. Required for sell orders. | | `orderType` | string | No | `buy` or `sell` (default: `buy`) | | `paymentMethodId` | string | No | Filter by payment method | | `country` | string | No | ISO 2-letter country code. Auto-detected from IP if omitted. | Either `fiatAmount` or `cryptoAmount` must be provided. ### Response ```json theme={null} { "success": true, "data": { "quotes": [ { "gatewayId": "gateway_a", "gatewayName": "Gateway A", "gatewayLogo": "https://...", "available": true, "fiatAmount": "100", "fiatCurrency": "USD", "cryptoAmount": "0.03842", "cryptoCurrency": "ETH", "network": "ethereum", "fees": { "processingFee": "2.50", "networkFee": "0.80", "totalFee": "3.30", "feePercentage": "3.3" }, "exchangeRate": "2602.81", "estimatedTime": "5-10 minutes", "kycRequired": "light", "expiresAt": 1706900000000, "rank": 1, "isBestRate": true, "score": 92 }, { "gatewayId": "gateway_b", "gatewayName": "Gateway B", "gatewayLogo": "https://...", "available": true, "fiatAmount": "100", "fiatCurrency": "USD", "cryptoAmount": "0.03801", "cryptoCurrency": "ETH", "network": "ethereum", "fees": { "processingFee": "3.00", "networkFee": "1.00", "totalFee": "4.00", "feePercentage": "4.0" }, "exchangeRate": "2630.89", "estimatedTime": "1-5 minutes", "kycRequired": "none", "expiresAt": 1706900000000, "rank": 2, "isBestRate": false, "score": 85 } ], "bestQuote": { "gatewayId": "gateway_a", "..." : "..." }, "fastestQuote": { "gatewayId": "gateway_b", "..." : "..." }, "cheapestFees": { "gatewayId": "gateway_a", "..." : "..." }, "unavailableGateways": [] } } ``` ### Quote Fields | Field | Type | Description | | --------------- | ------- | ------------------------------------------------------ | | `gatewayId` | string | Gateway identifier | | `gatewayName` | string | Display name | | `gatewayLogo` | string | Logo URL | | `available` | boolean | Whether this gateway can service the request | | `fiatAmount` | string | Fiat amount | | `cryptoAmount` | string | Crypto amount the user will receive | | `fees` | object | Fee breakdown (processing, network, total, percentage) | | `exchangeRate` | string | Exchange rate (1 crypto = X fiat) | | `estimatedTime` | string | Estimated processing time | | `kycRequired` | string | `none`, `light`, or `full` | | `expiresAt` | number | Quote expiry timestamp (milliseconds) | | `rank` | number | Ranking position (1 = best) | | `isBestRate` | boolean | Whether this is the best rate | | `isRecommended` | boolean | Whether this is the recommended gateway | | `score` | number | Routing score (0-100) | ### Ranked Results The response includes convenience fields for common selection strategies: | Field | Description | | --------------------- | ------------------------------------------------------------- | | `bestQuote` | Quote with the best exchange rate (most crypto for your fiat) | | `fastestQuote` | Quote with the shortest estimated processing time | | `cheapestFees` | Quote with the lowest total fees | | `unavailableGateways` | Gateways that couldn't provide a quote, with reasons | *** ## Create Checkout Intent Creates an order with a specific gateway and returns a checkout URL for payment. ``` POST /public/v1/onramp/checkout-intent ``` ### Request Body | Parameter | Type | Required | Description | | -------------------- | ------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `projectId` | string (UUID) | Yes | Your project ID | | `gateway` | string | Yes | Gateway ID from the supported config | | `fiatCurrency` | string | Yes | Fiat currency code | | `cryptoCurrency` | string | Yes | Crypto currency code | | `network` | string | Yes | Network ID | | `fiatAmount` | string | One required | Fiat amount | | `cryptoAmount` | string | One required | Crypto amount | | `walletAddress` | string | Buy orders | Destination wallet address (required for buy) | | `customerId` | string | No | Internal customer UUID | | `externalCustomerId` | string | No | Partner's external customer ID | | `orderType` | string | No | `buy` or `sell` (default: `buy`) | | `paymentMethodId` | string | No | Payment method ID | | `email` | string | No | Customer email | | `redirectUrl` | string | No | URL to redirect after checkout | | `metadata` | object | No | Provider-facing string map, passed to provider's `createOrder()`. Not persisted in order metadata. | | `partnerMetadata` | object | No | Partner data (`Record`). Persisted as `order.metadata.partnerMetadata` and included in webhook payloads. Max 20 keys, 4KB, 2 levels of nesting. | | `country` | string | No | ISO 2-letter country code | ### Request Example ```json theme={null} { "projectId": "550e8400-e29b-41d4-a716-446655440000", "gateway": "gateway_a", "fiatCurrency": "USD", "fiatAmount": "100", "cryptoCurrency": "ETH", "network": "ethereum", "walletAddress": "0x742d35Cc6634C0532925a3b844Bc9e7595f1bD21", "externalCustomerId": "user_123", "email": "user@example.com", "redirectUrl": "https://myapp.com/purchase-complete", "partnerMetadata": { "partnerOrderId": "order_abc", "campaign": "summer2026" } } ``` ### Response ```json theme={null} { "success": true, "data": { "orderId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "gateway": "gateway_a", "status": "pending", "checkout": { "method": "iframe", "url": "https://checkout.gateway-a.com/...", "expiresAt": 1706903600000, "allowedFeatures": ["payment"] } } } ``` ### Checkout Methods | Method | Description | How to Use | | ---------- | ------------------------------- | ------------------------------------ | | `iframe` | Embed checkout in an iframe | Load `checkout.url` in an `