Get Prices
Retrieve paywall prices and their corresponding IDs for use in checkout creation and subscription management.
Server-Side Only: This is a server-side API that requires authentication with your API key.
Overview
The Get Prices API endpoint allows you to retrieve all available prices for a specific paywall. This is essential for:
- Dynamic pricing displays - Show current prices in your application
- Checkout creation - Get price IDs for creating checkout sessions
- Plan comparison - Build pricing tables and comparison views
- Integration setup - Programmatically access pricing information
API Reference
Endpoint
GET https://onlineapp.pro/api/v1/paywall/{paywallId}/prices
Authentication
Include the x-api-key
header with your API key.
Get your API key
Get your paywall ID
Navigate to your paywall settings page and get the ID from the Paywall ID field:
URL Parameters
Parameter | Type | Required | Description |
---|---|---|---|
paywallId | string | Yes | Your paywall identifier |
Response Format
{
"error": null,
"data": [
{
"id": 98,
"unit_amount": 9.99,
"interval": "month"
},
{
"id": 99,
"unit_amount": 59.99,
"interval": "year"
}
],
"count": null,
"status": 200,
"statusText": "OK"
}
Response Fields
Field | Type | Description |
---|---|---|
error | string | Error message if request failed, null if successful |
data | array | Array of price objects |
count | number | Number of prices returned (null in this endpoint) |
status | number | HTTP status code |
statusText | string | HTTP status text |
Price Object Fields
Field | Type | Description |
---|---|---|
id | number | Unique price identifier |
unit_amount | number | Price amount (in your currency) |
interval | string | Billing interval: “month”, “year”, “lifetime” |
Basic Usage
Sample Implementation
const paywallId = '123';
const response = await fetch(`https://onlineapp.pro/api/v1/paywall/${paywallId}/prices`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'your-secret-api-key'
}
});
const result = await response.json();
if (result.error) {
console.error('Error:', result.error);
} else {
console.log('Prices:', result.data);
}
Error Handling
Common Error Responses
Status | Error | Description |
---|---|---|
400 | Bad Request | Invalid paywall ID format |
401 | Unauthorized | Invalid or missing API key |
404 | Not Found | Paywall not found |
500 | Internal Error | Server error |
Error Handling Example
const safeFetchPrices = async (paywallId, apiKey) => {
try {
const response = await fetch(`https://onlineapp.pro/api/v1/paywall/${paywallId}/prices`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey
}
});
if (!response.ok) {
let errorMessage = 'Unknown error occurred';
switch (response.status) {
case 400:
errorMessage = 'Invalid paywall ID provided.';
break;
case 401:
errorMessage = 'Authentication failed. Please check your API key.';
break;
case 404:
errorMessage = 'Paywall not found. Please verify the paywall ID.';
break;
default:
errorMessage = 'Unable to fetch prices. Please try again later.';
}
throw new Error(errorMessage);
}
const result = await response.json();
if (result.error) {
throw new Error(result.error);
}
return result.data;
} catch (error) {
console.error('Price fetch error:', error);
throw error;
}
};
Security Guidelines
1. Store API keys securely
// Good: Server-side environment variable
const apiKey = process.env.PAYWALL_API_KEY;
// Bad: Client-side exposure
// const apiKey = 'your-api-key'; // Never do this!
2. Use HTTPS for all requests
All API requests must use HTTPS to ensure secure communication.
Next Steps
Last updated on