Integrating a third-party verification service into your application requires more than just firing off HTTP requests. When dealing with registration checks, your application must be resilient to transient network issues, rate limits, and service-side maintenance.
In this guide, we will walk through how to build a robust client for the TG Validator API, focusing on interpreting error codes and managing state transitions effectively.
1. Establishing the Request Contract
TG Validator uses a synchronous request-response model. When you send a request to POST /api/v1/check, you receive a result immediately. To ensure your requests are accepted, you must adhere to the following structure:
-
Headers: Include your
X-API-Keyand setContent-Type: application/json. -
Payload: Provide a JSON body containing
{"service_type": "tg", "identifier": "<E.164 number>"}.
2. Implementing Error Handling Logic
Because the API returns a structured envelope (code, msg, data), you should evaluate both the HTTP status code and the internal response code. Here is how to handle the most common scenarios:
Authentication Errors (401 / 40100)
If you receive a 401, your X-API-Key is missing or invalid.
- Action: Ensure your key is correctly passed in the header. If the key has been rotated or revoked, generate a new one via the dashboard.
Balance Management (402 / 40200)
This indicates insufficient funds to perform the check.
- Action: Do not immediately retry. Check your balance in the dashboard, perform a top-up, and then re-queue the request.
Rate Limiting and Concurrency (429 / 42900)
TG Validator enforces a 200-requests-per-minute limit and a 3-concurrent-checks limit per user.
- Action: Implement a backoff strategy. If you hit this limit, stop immediate retries and wait before attempting the request again. Ensure your automation logic respects the concurrency limit to avoid repeated 429 errors.
Service Maintenance (503 / 50300)
If the verification service is temporarily unavailable, the API returns a 503.
- Action: Do not classify the phone number as "not registered." Because the API automatically refunds failed or undetermined checks, simply wait for the service to return to an operational state before retrying.
3. Best Practices for Production
- Validate Input: Ensure all phone numbers are formatted in E.164 before making the API call to avoid unnecessary errors.
-
Log Context: When debugging, keep track of your
transaction_idand theservice_type. If you need to contact support, provide these details along with the error code, but never share your API key in plain text. -
Interpret Results Carefully: Remember that a
registered: trueresult is only a signal of account presence at the time of the check. It does not provide proof of identity, consent, or current reachability.
Conclusion
By treating error codes as actionable signals rather than generic failures, you can build a stable integration that handles the realities of distributed services. Always prioritize graceful degradation—especially during maintenance windows—to ensure your application remains reliable for your end users.
This article was drafted with AI assistance and reviewed before publishing.
Top comments (0)