Skip to main content

Response Structure

All Pandabase API responses follow a consistent format that includes an ok field to indicate success or failure.

Success Response

When a request succeeds, the API returns ok: true along with the requested data:
{
  "ok": true,
  "data": {
    // Your requested data here
  }
}
Response Fields:
ok
boolean
required
Always true for successful requests
data
object
required
The requested resource or response data. The structure varies by endpoint.

Error Response

When a request fails, the API returns ok: false along with error details:
{
  "ok": false,
  "error": {
    "code": "error_code",
    "message": "Human-readable error message"
  }
}
Response Fields:
ok
boolean
required
Always false for failed requests
error
object
required
Error details containing code and message
code
string
required
Machine-readable error code (e.g., invalid_request, not_found, rate_limit_exceeded)
message
string
required
Human-readable error message explaining what went wrong
Error messages are designed to not contain sensitive information and can be safely displayed in user interfaces.

HTTP Status Codes

The API uses standard HTTP status codes to indicate the general category of response:
Status CodeDescription
200OK - Request succeeded
201Created - Resource created successfully
400Bad Request - Invalid request parameters
401Unauthorized - Missing or invalid authentication
403Forbidden - Authenticated but lacks permission
404Not Found - Resource doesn’t exist
409Conflict - Request conflicts with current state
422Unprocessable Entity - Validation error
429Too Many Requests - Rate limit exceeded
500Internal Server Error - Server error
503Service Unavailable - Temporary service interruption

Common Error Codes

Here are some common error codes you may encounter:
Error CodeHTTP StatusDescription
invalid_request400The request was malformed or missing required parameters
authentication_required401Valid authentication credentials are required
invalid_api_key401The provided API key is invalid or expired
insufficient_permissions403Your account doesn’t have permission for this action
not_found404The requested resource doesn’t exist
resource_already_exists409A resource with this identifier already exists
validation_error422One or more fields failed validation
rate_limit_exceeded429Too many requests, please slow down
internal_error500An unexpected error occurred on our servers

Example Responses

Successful GET Request

{
  "ok": true,
  "data": {
    "id": "pmnt_1234567890",
    "amount": 1000,
    "currency": "USD",
    "status": "succeeded",
    "created_at": "2024-12-25T10:00:00Z"
  }
}

Successful POST Request

{
  "ok": true,
  "data": {
    "id": "prod_abc123",
    "name": "Premium Plan",
    "price": 2999,
    "created_at": "2024-12-25T10:00:00Z"
  }
}

Validation Error

{
  "ok": false,
  "error": {
    "code": "validation_error",
    "message": "The 'email' field is required and must be a valid email address."
  }
}

Not Found Error

{
  "ok": false,
  "error": {
    "code": "not_found",
    "message": "The requested payment could not be found."
  }
}

Rate Limit Error

{
  "ok": false,
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Rate limit exceeded. Please retry after the reset time."
  }
}

Handling Responses

Always check the ok field to determine if a request succeeded:
const response = await fetch('https://pandabase.io/api/payments', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer sk_v3_xxx',
    'Content-Type': 'application/json'
  }
});

const result = await response.json();

if (result.ok) {
  // Success - use result.data
  console.log('Payment:', result.data);
} else {
  // Error - handle result.error
  console.error(`Error ${result.error.code}: ${result.error.message}`);
}
Use the X-Request-Id header from the response when reporting issues to support. This helps us quickly identify and resolve problems.