Skip to main content

Error Handling

The API uses standard HTTP status codes and returns detailed error information in a consistent format.

Error Response Format

All errors return a JSON object with the following structure:
{
  "error": {
    "code": "error_code",
    "message": "Human-readable error message",
    "request_id": "req_abc123def456",
    "details": {}
  }
}
Save the request_id from error responses. When contacting support, include this ID for faster troubleshooting.

HTTP Status Codes

StatusDescription
200Success
201Created - Resource successfully created
400Bad Request - Invalid parameters or validation failed
401Unauthorized - Invalid, missing, or expired API key
403Forbidden - Insufficient permissions or scope
404Not Found - Requested resource doesn’t exist
429Too Many Requests - Rate limit exceeded (see Rate Limits)
500Internal Server Error - Unexpected server error

Error Codes Reference

Authentication Errors (401)

CodeDescription
missing_api_keyNo API key provided in the Authorization header
invalid_auth_formatAuthorization header not using Bearer scheme
invalid_api_keyAPI key format is invalid or key doesn’t exist
api_key_revokedAPI key has been revoked
api_key_expiredAPI key has expired
organization_not_foundOrganization associated with API key no longer exists

OAuth Errors (401/403)

CodeDescription
oauth_invalid_tokenOAuth access token is invalid, expired, or revoked
oauth_insufficient_scopeToken doesn’t have required scopes for this endpoint

Device Auth Errors (400)

CodeDescription
authorization_pendingUser hasn’t approved/denied yet (keep polling)
slow_downPolling too fast. Increase interval by 5 seconds
access_deniedUser denied the authorization request
expired_tokenDevice code has expired. Start a new flow

Validation Errors (400)

CodeDescription
validation_errorRequest body failed validation. Check details.issues
invalid_requestRequest format is invalid

Server Errors (500)

CodeDescription
internal_errorUnexpected server error

Handling Errors

JavaScript/TypeScript

try {
  const response = await fetch('https://api.v2.dealmachine.com/v1/account', {
    headers: {
      'Authorization': `Bearer ${apiKey}`,
    },
  });

  if (!response.ok) {
    const { error } = await response.json();

    switch (error.code) {
      case 'invalid_api_key':
        console.error('Check your API key');
        break;
      case 'validation_error':
        console.error('Validation issues:', error.details?.issues);
        break;
      default:
        console.error('Error:', error.message);
    }
    return;
  }

  const data = await response.json();
} catch (err) {
  console.error('Network error:', err);
}

Python

import requests

response = requests.get(
    'https://api.v2.dealmachine.com/v1/account',
    headers={'Authorization': f'Bearer {api_key}'}
)

if not response.ok:
    error = response.json()['error']

    if error['code'] == 'invalid_api_key':
        print('Check your API key')
    elif error['code'] == 'validation_error':
        for issue in error.get('details', {}).get('issues', []):
            print(f"Validation error in {issue['path']}: {issue['message']}")
    else:
        print(f"Error: {error['message']}")

Validation Error Details

When you receive a validation_error, the details.issues array contains specific validation failures:
{
  "error": {
    "code": "validation_error",
    "message": "Validation failed",
    "request_id": "req_7f8a9b0c1d2e3f4g",
    "details": {
      "issues": [
        {
          "path": "client_id",
          "message": "Required"
        }
      ]
    }
  }
}

Response Headers

Every response includes:
HeaderDescription
X-Request-IdUnique request ID for debugging and support