API Errors
Understanding and handling errors returned by the ReachScore API.
Error Response Format
All API errors follow a consistent JSON structure:
{
"error": {
"type": "invalid_request_error",
"code": "invalid_email_format",
"message": "The email address is not valid.",
"field": "from_address",
"fix": "Use a valid email address format like user@example.com.",
"doc_url": "https://docs.reachscore.co/docs/api/errors#invalid_email_format",
"request_id": "req_abc123xyz"
}
}| Field | Description |
|---|---|
| type | The category of error (see Error Types below) |
| code | A machine-readable error code |
| message | A human-readable description |
| field | The request field that caused the error (if applicable) |
| fix | Suggested action to resolve the error |
| doc_url | Link to relevant documentation |
| request_id | Unique request identifier for support |
Error Types
The type field categorizes errors into the following types:
authentication_errorHTTP 401Authentication failed. The API key is missing, invalid, or expired.
authorization_errorHTTP 403The API key does not have permission for this operation. Check your key scopes.
invalid_request_errorHTTP 400The request is malformed or contains invalid parameters. Check the field property for details.
not_found_errorHTTP 404The requested resource does not exist or is not accessible with your API key.
conflict_errorHTTP 409A conflicting operation is in progress. Often caused by idempotency key reuse with different parameters.
rate_limit_errorHTTP 429Too many requests. Implement exponential backoff and check the Retry-After header.
api_errorHTTP 500An internal server error occurred. These are rare and typically transient. Retry with backoff.
Common Error Codes
| Code | Description |
|---|---|
| api_key_missing | No API key provided in the Authorization header |
| api_key_invalid | The API key does not exist or has been revoked |
| insufficient_scope | The API key lacks the required scope for this operation |
| invalid_email_format | The provided email address is not valid |
| invalid_url | The provided URL is invalid or blocked (SSRF protection) |
| resource_not_found | The requested resource does not exist |
| domain_not_verified | The domain must be verified before this operation |
| rate_limit_exceeded | Too many requests in the current time window |
| quota_exceeded | Monthly test limit reached for your plan |
| idempotency_key_conflict | Same idempotency key used with different request body |
Handling Errors
Here is a recommended pattern for error handling:
async function createTest(params) {
try {
const response = await fetch('https://api.reachscore.co/v1/tests', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify(params),
});
if (!response.ok) {
const data = await response.json();
const error = data.error;
switch (error.type) {
case 'authentication_error':
throw new Error('Invalid API key. Please check your credentials.');
case 'invalid_request_error':
throw new Error(`Validation error on ${error.field}: ${error.message}`);
case 'rate_limit_error':
const retryAfter = response.headers.get('Retry-After');
throw new Error(`Rate limited. Retry after ${retryAfter}s`);
case 'quota_exceeded':
throw new Error('Monthly limit reached. Upgrade your plan.');
default:
throw new Error(error.message);
}
}
return await response.json();
} catch (err) {
console.error('API Error:', err);
throw err;
}
}Getting Help
Include the request_id when contacting support. This helps us quickly locate and diagnose the issue.