ReachScore Docs

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"
  }
}
FieldDescription
typeThe category of error (see Error Types below)
codeA machine-readable error code
messageA human-readable description
fieldThe request field that caused the error (if applicable)
fixSuggested action to resolve the error
doc_urlLink to relevant documentation
request_idUnique request identifier for support

Error Types

The type field categorizes errors into the following types:

authentication_errorHTTP 401

Authentication failed. The API key is missing, invalid, or expired.

authorization_errorHTTP 403

The API key does not have permission for this operation. Check your key scopes.

invalid_request_errorHTTP 400

The request is malformed or contains invalid parameters. Check the field property for details.

not_found_errorHTTP 404

The requested resource does not exist or is not accessible with your API key.

conflict_errorHTTP 409

A conflicting operation is in progress. Often caused by idempotency key reuse with different parameters.

rate_limit_errorHTTP 429

Too many requests. Implement exponential backoff and check the Retry-After header.

api_errorHTTP 500

An internal server error occurred. These are rare and typically transient. Retry with backoff.

Common Error Codes

CodeDescription
api_key_missingNo API key provided in the Authorization header
api_key_invalidThe API key does not exist or has been revoked
insufficient_scopeThe API key lacks the required scope for this operation
invalid_email_formatThe provided email address is not valid
invalid_urlThe provided URL is invalid or blocked (SSRF protection)
resource_not_foundThe requested resource does not exist
domain_not_verifiedThe domain must be verified before this operation
rate_limit_exceededToo many requests in the current time window
quota_exceededMonthly test limit reached for your plan
idempotency_key_conflictSame 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.