How to Debug a Third-Party API Integration
- Author
- Vishal Maurya
- Published on
- Reading time
- 2 min read
Overview
An integration can fail even when your own application is healthy: credentials may expire, the provider may rate-limit you, a response schema may change, or a network request may hang. Treat the external API as an unreliable dependency.
Record the endpoint, latency, status code, provider request ID, retry count, and a redacted error category. Define a total timeout budget that fits the user workflow, rather than allowing an outbound call to consume the whole request lifetime.
Make the integration resilient
- Separate connection and read timeouts.
- Validate required fields and types before saving a provider response.
- Retry only transient failures such as selected timeouts,
429, or5xx, and respectRetry-Afterwhere applicable. - Use exponential backoff with jitter and a retry limit.
- Make write operations idempotent or use provider idempotency keys.
- Alert on sustained failure rates rather than one isolated request.
Example: a concrete starting point
import requests
from requests import RequestException
def fetch_customer(base_url: str, token: str, customer_id: str) -> dict:
try:
response = requests.get(
f"{base_url}/customers/{customer_id}",
headers={"Authorization": f"Bearer {token}"},
timeout=(3.05, 10),
)
response.raise_for_status()
payload = response.json()
except (RequestException, ValueError) as exc:
raise RuntimeError("Customer provider request failed") from exc
if not isinstance(payload, dict) or "id" not in payload:
raise RuntimeError("Customer provider returned an unexpected response")
return payload
The example illustrates the boundary and validation pattern; adapt names, persistence, error handling, and provider-specific details to your application. It is not a complete production system by itself.
Failure cases to test
Do not log authorization headers, payment details, or full sensitive payloads. A 400 usually needs input or contract correction, not repeated retries. A retry after a timeout can duplicate a write if the provider completed it but the response was lost.
Before release, test the happy path, invalid input, missing permissions, dependency failure, and a retry or duplicate request where relevant. Record expected behavior so the implementation can be reviewed against the real business requirement.
When to bring in a developer
I can build or repair integrations with external APIs, including authentication, schema validation, retry behavior, and production diagnostics.
Conclusion
The reliable version of this feature is not just the happy-path demo. It makes ownership, validation, authorization, failure handling, and operational behavior explicit. Start with the smallest useful workflow, measure it against real data, and expand only when the next requirement is clear.