The Chomp database contains millions of branded food products indexed primarily by GTIN-12 (UPC-A) and GTIN-13 (EAN-13) barcode formats.
If you are calling the /food/branded/barcode.php endpoint and receiving empty results or a 404, the issue is often caused by barcode formatting inconsistencies, scanner inaccuracies, or alternate GTIN representations of the same product.
Before assuming a product does not exist in the database, implement the following fallback logic in your application:
If the barcode is a valid 12-digit UPC-A code, prepend a leading 0 and retry the request.
Example
012345678905 → 0012345678905
If the barcode is a valid 8-digit EAN-8 code, prepend five leading zeroes and retry.
Example
12345670 → 0000012345670
Some products may be stored without leading zeroes. Remove all leading zeroes and retry the lookup.
Example
00012345678905 → 12345678905
A resilient barcode lookup implementation typically follows this sequence:
1. Original barcode lookup
2. UPC-A → EAN-13 conversion
3. EAN-8 zero-padding
4. Leading zero stripping
5. Prompt user to rescan or manually enter barcode
6. Fallback to /food/branded/name.php search
Mobile barcode scanners are not always reliable, especially in:
These conditions can result in:
You should validate barcode check-digits before sending requests to the API. This prevents malformed barcode queries and reduces unnecessary API calls.
This is especially important when using mobile-device camera scanners.
If an invalid barcode is submitted to Chomp, the API may correctly return no results even if the product exists in the database.
Always provide users with:
This significantly improves lookup success rates in real-world conditions.
If barcode matching fails entirely, prompt the user to search by product name using:
/food/branded/name.php
In some cases:
Name search is often the best fallback for recovering these cases.
If:
then the product may not yet exist in the Chomp database.
Chomp monitors failed barcode queries and periodically prioritizes adding high-frequency missing products during database updates.
UPC-E barcodes are compressed representations of UPC-A codes. Depending on the scanner or barcode library you use, UPC-E values may:
For best compatibility, normalize UPC-E scans into standard UPC-A or EAN-13 representations before querying the API.
function generateBarcodeCandidates(barcode) {
const candidates = new Set();
// Original
candidates.add(barcode);
// UPC-A -> EAN-13
if (/^\d{12}$/.test(barcode)) {
candidates.add(`0${barcode}`);
}
// EAN-8 -> padded GTIN
if (/^\d{8}$/.test(barcode)) {
candidates.add(`00000${barcode}`);
}
// Strip leading zeroes
candidates.add(barcode.replace(/^0+/, ''));
return [...candidates];
}
/food/branded/barcode.php
/food/branded/name.php
For more information about UPC and EAN interoperability, see: