Easypay uses standard HTTP response status codes to indicate the success or failure of API requests.
The API uses three main ranges of status codes:
- 2xx Success: Your request was successful
- 4xx Client Error: There was an error with the information you provided
- 5xx Server Error: An error occurred on Easypay's servers (rare)
| Status Code | Meaning | What to Do |
|---|---|---|
200 OK | Request successful | Process the response |
201 Created | Resource created successfully | Process the newly created resource |
204 No Content | Request successful, no content to return | Continue normally |
400 Bad Request | Invalid request parameters | Check your request payload |
403 Forbidden | Authentication failed | Verify your credentials |
404 Not Found | Resource doesn't exist | Check the resource ID |
409 Conflict | Request conflicts with current state | Review the conflict details |
429 Too Many Requests | Rate limit exceeded | Slow down your requests |
500 Internal Server Error | Server error | Retry or contact support |
502 Bad Gateway | Temporary server issue | Retry the request |
503 Service Unavailable | Service temporarily unavailable | Retry the request |
When an error occurs, the API returns a JSON response with error details:
{
"status": "error",
"message": "Error description",
"code": "ERROR_CODE",
"doc_url": "https://docs.easypay.pt/errors/ERROR_CODE"
}Possible Causes:
- Missing or invalid
AccountIdorApiKeyheaders - Account has been blocked
- Insufficient permissions for the requested action
Example:
{
"status": "error",
"message": "Authentication Error: Invalid AccountId or ApiKey",
"code": "AUTHENTICATION_ERROR"
}Resolution: Verify your credentials and ensure your account is active.
Cause: You provided an invalid or unsupported Content-Type header.
Example:
{
"status": "error",
"message": "Invalid Content Type Error: Unsupported content type",
"code": "INVALID_CONTENT_TYPE"
}Resolution: Set the Content-Type header to application/json.
Cause: The request body contains malformed JSON.
Example:
{
"status": "error",
"message": "Invalid JSON Error: Unexpected token",
"code": "INVALID_JSON"
}Resolution: Validate your JSON payload before sending the request.
Cause: Required parameters are missing or invalid.
Example:
{
"status": "error",
"message": "Invalid Params Error: Field 'value' is required",
"code": "INVALID_PARAMS",
"doc_url": "https://docs.easypay.pt/errors/INVALID_PARAMS"
}Resolution: Review the error message and ensure all required parameters are provided with valid values.
Cause: An unexpected error occurred on Easypay's servers.
Example:
{
"status": "error",
"message": "Internal Error: An unexpected error occurred",
"code": "INTERNAL_ERROR"
}Resolution: Retry the request. If the problem persists, contact support.
Some errors are safe to retry, while others are not. The API includes an X-Easypay-Should-Retry header to help you decide:
X-Easypay-Should-Retry: trueSafe to Retry (when X-Easypay-Should-Retry: true or for these status codes):
409 Conflict- May indicate the original request is still in transit429 Too Many Requests- Wait and retry502 Bad Gateway- Temporary server issue503 Service Unavailable- Service temporarily down
Do NOT Retry:
400 Bad Request- Fix your request first403 Forbidden- Fix authentication first404 Not Found- Resource doesn't exist422 Unprocessable Entity- Fix validation errors first
If the X-Easypay-Should-Retry header is not present, use this strategy:
- No response received: Retry the request
- Status code 409, 429, 502, or 503: Retry the request
- Status code 500 on non-POST requests: Retry the request
- Status code 500 on POST requests: Do NOT retry (may duplicate resources)
- All other errors: Do NOT retry
async function retryableRequest(url, options, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
const response = await fetch(url, options);
// Check if we should retry
const shouldRetry = response.headers.get('X-Easypay-Should-Retry');
if (shouldRetry === 'true' || [409, 429, 502, 503].includes(response.status)) {
if (i < maxRetries - 1) {
await sleep(Math.pow(2, i) * 1000); // Exponential backoff
continue;
}
}
return response;
} catch (error) {
if (i < maxRetries - 1) {
await sleep(Math.pow(2, i) * 1000);
continue;
}
throw error;
}
}
}- Always Check Status Codes: Don't assume requests succeed
- Log Errors: Keep detailed logs of errors for debugging
- Handle Errors Gracefully: Provide meaningful feedback to users
- Use Idempotency: Use idempotency keys for safe retries (see Idempotency)
- Implement Exponential Backoff: When retrying, increase wait time between attempts
- Monitor Error Rates: Track error rates to identify issues early
- Respect Rate Limits: Implement rate limiting to avoid 429 errors
- Idempotency - Learn about safe retries with idempotency keys
- Authentication - Fix authentication errors
- Quick Start - Make your first successful API call