Search and Fetch

Guide / Products and prices

How to look up a product by barcode: GTIN, UPC, EAN and ASIN

A product name can match two different items; its barcode can't. How to check a barcode, put it in one standard form and look it up for free.

Search and Fetch desk · · 6 min readShare

Open Food Facts holds two Nutella records with the same name, the same brand and the same 400 g jar, under two different barcodes. An agent that matches products by name would merge them; one that matches by barcode keeps them apart. That is why a shopping agent should pin down the barcode before it compares prices or reads reviews.

Four acronyms do most of the work. A GTIN, or Global Trade Item Number, is the number itself. UPC (Universal Product Code) and EAN (originally the European Article Number) are the two common barcode styles that print it: a UPC-A barcode carries a 12-digit GTIN, an EAN-13 a 13-digit one and an EAN-8 an 8-digit one, so UPC and EAN name the symbol and GTIN names the number. An ASIN, or Amazon Standard Identification Number, is Amazon's own catalog number, separate from all of them. GS1, the standards body behind barcodes, issues GTINs and writes the rules this guide follows.

By the end, your agent will check a barcode, put it in one standard form and fetch the product's record for free from Open Food Facts' API. You need the printed number and an HTTP client that sends its own User-Agent.

How to look up a product by its barcode

  1. Read the number printed under the bars.
  2. Check the last digit. It is calculated from all the others, so a code that fails the check was read or typed wrong and isn't worth a request.
  3. Pad it to 14 digits for your own records, with two leading zeros for a 12-digit code and one for a 13-digit code, and store it as text, since GS1 US specifies a 14-digit text field filled with zeros on the left.
  4. Look the product up by the code as printed, with a User-Agent of the form AppName/Version (ContactEmail), and ask only for the fields you need with the fields parameter. Open Food Facts reads need no account.
  5. Past a few hundred products, download Open Food Facts' bulk export, as CSV or JSONL files, instead of calling once per item.

Codes that need a second look

  • A 14-digit code that starts with 1 to 9 belongs to a case or a carton, not the item on the shelf, and a 9 means the weight or count varies. A true GTIN-14 never starts with zero; a 14-digit code that does is a shorter GTIN padded out, since case barcodes always carry 14 digits.
  • A QR code on newer packaging may hold a GS1 Digital Link, a web address with the product number inside it. Take the 14 digits after /01/, as in GS1 US's example https://example.com/01/00614141000005.
  • Anything that isn't food, such as a beauty product or pet food: add product_type=all to the request. When the product lives on the server for its type, the API answers with a redirect, so follow it rather than treat it as a failure.

Example calls

We called the v2 product endpoint for barcode 3017624010701 and asked for five fields.

GET https://world.openfoodfacts.org/api/v2/product/3017624010701.json?fields=code,product_name,brands,quantity,categories

The call returned this record.

{
  "code": "3017624010701",
  "product": {
    "brands": "Ferrero",
    "categories": "Cocoa and hazelnuts spreads, de:Other",
    "code": "3017624010701",
    "product_name": "Nutella",
    "quantity": "400.0 g"
  },
  "status": 1,
  "status_verbose": "product found"
}

Open Food Facts now marks v2 as deprecated, though it still supports it, and recommends v3 for new integrations. Contributors supply the data voluntarily, and the project gives no assurance that it is accurate or complete, so treat every field as text to clean up: this record gives its quantity as 400.0 g.

This is one of the two Nutella records. Open Food Facts' own reference uses the other, 3017620422003, with the same name, the same brand and a quantity of 400g. GS1's rule is that a product gets a new GTIN when a change matters to the trading process, so two codes are a reason to keep two records apart until the agent knows why they differ.

The code from the call passes its check. Weight the digits before the check digit 3, 1, 3, 1 from the right, add up the results, and the check digit is whatever lifts the total to the next multiple of ten.

code without check digit:  3 0 1 7 6 2 4 0 1 0 7 0
read right to left:        0 7 0 1 0 4 2 6 7 1 0 3
weights:                   3 1 3 1 3 1 3 1 3 1 3 1
products:                  0 7 0 1 0 4 6 6 21 1 0 3   sum = 49
check digit:               50 - 49 = 1   -> 3017624010701 is valid
14-digit key:              03017624010701

Padding with zeros never changes the check digit, which is why the 14-digit key still ends in 1.

What it costs

Our lookup cost nothing. With Open Food Facts the limit is the rate, not the price: 15 product reads a minute per IP address and 10 searches a minute. If you exceed them, the project reserves the right to ban the address, and global limits return a 503.

By our arithmetic, 15 reads a minute is 900 an hour, so checking a 10,000-barcode catalog one call at a time from one IP address takes about 11 hours. That is why the export is the right path at scale. The data is published under the Open Database License.

UPCitemdb sells barcode lookups that accept a UPC, EAN, GTIN or ISBN. Its paid plans are subscriptions billed at the start of the month, even if you make no requests. The per-1,000 figures below are our arithmetic for a 30-day month at full daily use. UPCitemdb's plan page carries the current prices.

Plan Price Daily allowance Per 1,000 lookups at full use
Open Food Facts Free 15 reads a minute per IP address $0
UPCitemdb Explorer Free, no signup 100 requests, lookups and searches combined $0
UPCitemdb DEV $99 a month 20,000 lookups about 17¢; overage 40¢
UPCitemdb PRO $699 a month 150,000 lookups about 16¢; overage 40¢

Over the daily limit, UPCitemdb refuses requests with a 429 error by default, and the X-RateLimit-Remaining header says how many lookups are left.

When this is the wrong tool

A barcode lookup tells you what a product is, not what it sells for. UPCitemdb shows Amazon and eBay sales information on its website, but its affiliate agreements bar it from redistributing that data through the API. It points buyers to Amazon's Product Advertising API and eBay's Finding API instead, and those are the routes to use.

If you have only a name, you need search, not lookup. Open Food Facts' v2 structured search filters by fields such as category and brand, has no full-text search in the server API, and blocks clients that use it for search-as-you-type.

And watch for case codes: a case price set against a unit price is not like with like, which is the comparison this whole method exists to prevent.

Frequently asked questions

What is the difference between GTIN, UPC and EAN?

A GTIN (Global Trade Item Number) is the product number, and UPC-A (Universal Product Code) and EAN-13 (originally European Article Number) are barcodes that carry it, a 12-digit and a 13-digit GTIN respectively. GS1 US says a GTIN does not replace the U.P.C., because the U.P.C. is the barcode that encodes a GTIN-12.

What is an ASIN?

An ASIN (Amazon Standard Identification Number) is Amazon's own identifier for an item in its catalog, separate from the GTIN printed on the package. UPCitemdb's API includes the ASIN in a barcode record if the item ever showed on Amazon, which is one way to get from a barcode to Amazon's listing.

How do I calculate a GTIN check digit?

Weight the digits before the check digit 3, 1, 3, 1 starting from the right, add them up, and the check digit is the amount needed to reach the next multiple of ten. GS1 US offers a free calculator to confirm the result.

Can I look up a product by UPC for free?

Yes. Open Food Facts allows 15 product reads a minute per IP address with no account, and UPCitemdb's Explorer plan allows 100 requests a day without signing up.

Will 2D barcodes change barcode lookup?

GS1 US's Sunrise 2027 plan aims for 2D barcodes to be scanned at any retail checkout by the end of 2027. At a minimum, it requires price lookup systems to use the GTIN in a 2D code the same way they use it in a 1D barcode, so the GTIN stays the key.

Read this article as Markdown Open in ChatGPT Open in Claude