
A lookup API rarely breaks your app. A hurried client does. The same five mistakes show up in almost every integration we are asked to debug: trusting the HTTP status alone, crashing on a missing field, retrying in a tight loop, hiding the real error message and treating every failure the same. None of them are hard to fix.
1. Read the body, not just the status
A1 Plan API answers with JSON. Success is "ERROR": "0" (a string, not a number). Anything else means the request did not do what you wanted, and the human-readable reason is in Message. You will see messages such as Authentication fail, Insufficient balance or No active subscription. Please subscribe to a plan.
2. Normalise key casing once
Real responses are not perfectly uniform. DTH info endpoints use error in lower case, plan fetch returns MESSAGE while others return Message, and bill fetch returns its details under BILLDEATILS (yes, spelled that way). Do not scatter special cases through your code. Put one small wrapper at the edge:
function a1_call($url) {
$ch = curl_init($url);
curl_setopt_array($ch, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 15, CURLOPT_CONNECTTIMEOUT => 5));
$raw = curl_exec($ch);
$err = curl_errno($ch);
curl_close($ch);
if ($err || $raw === false) { return array('ok' => false, 'retry' => true, 'message' => 'Network problem'); }
$j = json_decode($raw, true);
if (!is_array($j)) { return array('ok' => false, 'retry' => true, 'message' => 'Unexpected response'); }
$j = array_change_key_case($j, CASE_LOWER);
$ok = isset($j['error']) && (string)$j['error'] === '0';
return array('ok' => $ok, 'retry' => false, 'message' => isset($j['message']) ? $j['message'] : '', 'data' => $j);
}
After this, every caller reads $r['ok'] and $r['message'] and nothing else. Remember that nested keys keep their original spelling; only the top level is lower-cased here.
3. Set timeouts on purpose
Without a timeout, one slow upstream response can hold a web worker for minutes. We suggest roughly 5 seconds to connect and 15 seconds in total. If your customer is waiting on a screen, show a spinner for that long and then a calm message with a retry button.
4. Retry once, and only when it can help
| What you got | Retry? | Why |
|---|---|---|
| Timeout or connection error | Once, after a short pause | Likely transient |
| Non-JSON body | Once | Often a gateway hiccup |
| Authentication fail | No | Wrong or changed credentials; fix them |
| IP or e-KYC error | No | Needs a dashboard change, not a retry |
| No active subscription | No | Renew the plan |
| Daily limit reached | No, until tomorrow | More hits will not help |
Never loop. A retry storm during an upstream blip burns through your daily hits and makes the blip worse.
5. Log the Message, show a friendly one
Customers should see something like "We could not load plans right now. Please try again." Your logs should hold the raw Message, the endpoint and the time. When you contact support, that line is the fastest way for us to find the problem.
6. Watch your quota before it watches you
Call Usage Status when your app starts, or on an admin screen, to show hits used and hits left. It is free and returns your plan, days left and daily limit. Pair it with caching, covered in caching and daily limits.
A short checklist
- Success means the string
"0". - One wrapper, lower-cased keys, one place to handle failures.
- 15 second timeout, one retry for transient errors only.
- Log the raw message, show a friendly one.
- Alert yourself on repeated failures so you hear about it before customers do.
The first call is in the quickstart; the full list of fields is in the documentation.
Frequently asked questions
How do I know an A1 Plan API call succeeded?
Check that the ERROR field (or error on DTH endpoints) equals the string "0". Any other value is a failure; read the Message field for the reason.
Should I retry failed calls?
Retry once after a timeout or network error. Do not retry authentication, IP, e-KYC or subscription errors because repeating them cannot succeed and each attempt counts as a hit.
Are lookup calls safe to repeat?
Yes, they are read-only, so a repeat cannot create a duplicate. It does use one more of your daily hits.
Create an account, pick a plan and make your first call today. Every plan includes every endpoint.
Create account Read the docs


