BIN lookup with JavaScript
This page uses Node.js 18 or later. fetch is built in. Create an API key in the quickstart.
WARNING: Do not put the API key in browser code. Call the API from your server.
Store the key
export BINLOOKUP_API_KEY="your_key_here"
Look up one BIN
const apiKey = process.env.BINLOOKUP_API_KEY;
const response = await fetch("https://api.binlookupapi.com/v1/bin", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ number: 42467101 }),
});
const payload = await response.json();
if (response.status === 200) {
console.log(payload.data.scheme, payload.data.issuer.name);
console.log("Remaining:", response.headers.get("X-Quota-Remaining"));
} else if (response.status === 401) {
console.error("The API key is missing or not valid.");
} else if (response.status === 403) {
console.error(payload.error, payload.message);
} else if (response.status === 404) {
console.error("The BIN is not in the data.");
} else if (response.status === 429) {
console.error("The daily quota is used.");
} else if (response.status === 400) {
console.error(payload.message);
} else {
console.error(`The API returned HTTP ${response.status}.`);
}
payload.data contains the fields in the API reference. On BLAPI-150KPM and above, payload.meta.longer_bin_available is also present.
HTTP 403 is FORBIDDEN or FEATURE_NOT_AVAILABLE. Read payload.error. Some error bodies also contain upgrade_url.
Look up many BINs
POST /v1/bins accepts 1 to 2,000 values. It requires BLAPI-500KPM, or a test-mode organisation. Each value uses one lookup.
const response = await fetch("https://api.binlookupapi.com/v1/bins", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.BINLOOKUP_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ numbers: [400062, "400597", 99999999] }),
});
const payload = await response.json();
if (response.status === 403 && payload.error === "FEATURE_NOT_AVAILABLE") {
console.error("Batch lookup needs the BLAPI-500KPM plan.");
} else if (response.status === 200) {
for (const item of payload.results) {
if (item.data) {
console.log(item.number, item.data.scheme);
} else {
console.log(item.number, item.error);
}
}
} else if (response.status === 429) {
console.error("Remaining:", response.headers.get("X-Quota-Remaining"));
}
A 429 on a batch that does not fit uses no quota. X-Quota-Remaining is the real remainder. See Batch lookups.