Error Handling
The Prediko API uses conventional HTTP status codes to indicate success or failure.
HTTP Status Codes
Section titled “HTTP Status Codes”| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid or missing API key |
| 403 | Forbidden - Valid key but insufficient permissions |
| 404 | Not Found - Resource doesn’t exist |
| 500 | Internal Error - Something went wrong on our end |
Error Response Format
Section titled “Error Response Format”All error responses follow this structure:
{ "detail": "Human-readable error message"}Common Errors
Section titled “Common Errors”Authentication Errors (401)
Section titled “Authentication Errors (401)”{ "detail": "Missing Authorization header"}Solutions:
- Ensure you include the
Authorizationheader - Use the format:
Authorization: Bearer YOUR_API_KEY - Check that your API key is valid and not expired
Not Found Errors (404)
Section titled “Not Found Errors (404)”{ "detail": "Order 'ord_invalid' not found"}Solutions:
- Verify the resource ID is correct
- Check that the resource exists in your tenant
Handling Errors in Code
Section titled “Handling Errors in Code”import requests
response = requests.get( "https://api.prediko.io/api/v1/orders/ord_123", headers={"Authorization": "Bearer YOUR_API_KEY"})
if response.status_code == 200: order = response.json()elif response.status_code == 401: print("Authentication failed. Check your API key.")elif response.status_code == 404: print("Order not found.")else: print(f"Error: {response.json().get('detail')}")try { const response = await fetch( "https://api.prediko.io/api/v1/orders/ord_123", { headers: { "Authorization": "Bearer YOUR_API_KEY" } } );
if (response.ok) { const order = await response.json(); } else if (response.status === 401) { console.error("Authentication failed."); } else if (response.status === 404) { console.error("Order not found."); }} catch (error) { console.error("Network error:", error);}