Error Medic

API Error Troubleshooting: Complete Guide to HTTP Status Codes & Fixes

API errors are an inevitable part of building modern software. Whether you're integrating a payment gateway, syncing data between platforms, or consuming a third-party service, understanding how to diagnose and resolve API errors quickly is essential to keeping your systems reliable and your users happy.

Most API errors fall into predictable categories. Authentication failures (401/403) usually mean expired credentials or misconfigured scopes. Rate limiting (429) signals you're sending requests too fast. Server errors (500/502/503) point to issues on the provider's end. Client errors (400/404/422) mean your request is malformed or targeting a resource that doesn't exist. The HTTP status code is always your first clue.

This section covers over 240 troubleshooting articles across 27 API providers, from payment platforms like Stripe and PayPal to collaboration tools like Slack and Discord, and infrastructure APIs from AWS, Azure, and GCP. Each article walks through specific error messages with step-by-step resolution steps, real code examples, and links to official documentation.

Whether you're debugging an OAuth token refresh at 3 AM or tracing why a webhook payload isn't arriving, these guides are designed to get you from error message to working code as fast as possible. We focus on practical, copy-paste solutions backed by official documentation and real-world production experience.

Browse by Category

Common Patterns & Cross-Cutting Themes

Authentication & Authorization Failures

The most common API errors are 401 Unauthorized and 403 Forbidden responses. A 401 means authentication failed entirely — your API key is invalid, your OAuth token expired, or you forgot to include credentials. A 403 means you authenticated successfully but your account or token lacks the required permissions.

The fix depends on your auth method. For API key auth, regenerate the key and verify it's being sent in the correct header (usually Authorization: Bearer <token> or a provider-specific header like X-API-Key). For OAuth, check that your refresh token flow is working and that you requested the right scopes during authorization. Many providers revoke tokens after a password change or security event, so check for recent account activity.

A subtle pitfall: some providers return 403 instead of 401 for security reasons (to avoid revealing whether a resource exists). Always check the response body for the actual error code and message rather than relying solely on the HTTP status.

Rate Limiting & Throttling

Nearly every API enforces rate limits, and hitting them is one of the most common issues in production systems. When you receive a 429 Too Many Requests response, the provider is telling you to slow down.

The correct approach is exponential backoff with jitter: start with a 1-second delay, double it on each retry, and add a random component to prevent thundering herd problems. Most APIs include rate limit headers (X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset) that let you proactively throttle before hitting the limit. Implement a token bucket or sliding window rate limiter on your side to stay within bounds.

For high-volume integrations, consider batching requests where the API supports it, caching responses locally, and distributing requests across time windows. Some providers offer higher rate limits on premium plans — if you're consistently hitting limits, it may be worth upgrading rather than engineering around them.

Timeout & Connection Errors

Timeout errors happen when a request takes longer than the client or server allows. They manifest as ETIMEDOUT, ECONNREFUSED, ESOCKETTIMEDOUT, or provider-specific timeout messages. Network instability, large payloads, and provider-side slowdowns are common causes.

Start by checking if the issue is on your end or theirs. Try the request with curl or Postman to rule out code-level issues. If the provider's status page shows degradation, implement a circuit breaker pattern to fail fast rather than piling up hanging connections. For legitimate large operations (bulk imports, report generation), look for async/polling patterns where you start a job and poll for completion rather than waiting synchronously.

Set reasonable timeouts in your HTTP client — 30 seconds is a common default, but some operations need more. Always set both connect and read timeouts independently.

Data Validation & Serialization Errors

400 Bad Request and 422 Unprocessable Entity errors mean your request payload doesn't match what the API expects. Common causes include missing required fields, wrong data types, invalid enum values, and character encoding issues.

Always validate your payload against the API's schema before sending. Pay attention to field name casing (camelCase vs. snake_case), date formats (ISO 8601 is standard but not universal), and numeric precision (especially for currency — always use the smallest unit like cents). When an API returns a validation error, the response body usually tells you exactly which field failed and why.

Watch for API version differences: a field that was optional in v1 might be required in v2. Pin your integration to a specific API version and test thoroughly before upgrading.

Webhook Reliability & Delivery Failures

Webhooks invert the usual request flow — the API provider calls your endpoint, and if it fails, you might never know. Common issues include misconfigured URLs, SSL certificate problems on your endpoint, and your server responding too slowly (most providers expect a 2xx response within 5–30 seconds).

Implement signature verification for every webhook to prevent spoofing. Each provider uses a different signing scheme — HMAC-SHA256 is the most common. Process webhook payloads asynchronously: accept the webhook, return 200 immediately, then process the event in a background job. This prevents timeout issues and lets you retry on your own terms.

Set up webhook monitoring: log every received event, track delivery success rates, and configure the provider's retry/notification settings. Most providers offer a webhook event log in their dashboard where you can inspect payloads and replay failed deliveries.

Quick Troubleshooting Guide

SymptomLikely CauseFirst Step
HTTP 401 UnauthorizedExpired or invalid API key / OAuth tokenRegenerate API key or refresh OAuth token; check Authorization header format
HTTP 403 ForbiddenInsufficient scopes or permissionsReview API key scopes; check IAM or RBAC permissions for the resource
HTTP 429 Too Many RequestsRate limit exceededImplement exponential backoff; check X-RateLimit headers; consider request batching
HTTP 400 Bad RequestMalformed request payloadValidate JSON body against API docs; check required fields and data types
HTTP 404 Not FoundWrong endpoint URL or deleted resourceVerify URL path, API version prefix, and resource ID existence
HTTP 500 Internal Server ErrorProvider-side issue (transient)Retry with exponential backoff; check provider status page
HTTP 502/503 Bad GatewayUpstream server overloaded or deployingWait 30–60 seconds and retry; check provider status page
ETIMEDOUT / ECONNREFUSEDNetwork issue or provider unreachableCheck network connectivity; verify DNS resolution; try from a different network
SSL/TLS handshake failureCertificate or TLS version mismatchUpdate CA certificate bundle; ensure TLS 1.2+ support
Empty or unexpected response bodyWrong Accept header or API versionSet Accept: application/json; check API version in URL or header

Category Deep Dives

Frequently Asked Questions