Barcode lookup

14 views
Skip to first unread message

Leo Perez

unread,
Dec 1, 2025, 8:48:19 PM (10 days ago) Dec 1
to fatsecret Platform API
Hi, so after setting up barcode search with the API, I noticed there is good amount of foods that populate results that are UPC-A but EAN-8 foods not much at all are in the FatSecret database (I haven't been able to scan one EAN-8 UPC that came back with the food details). I am doing the correct padding as well with the leading zeros.

Just wanted to make sure I'm correct in that there are little ean-8 upcs in the fat secret database?

The manual food search does populate the EAN-8 foods, so guessing there isn't that UPC correlation yet for a lot of food that have EAN-8 in the database?

Will this be getting updated as well to include a lot more foods?

seba...@fatsecret.com

unread,
Dec 1, 2025, 8:53:57 PM (10 days ago) Dec 1
to fatsecret Platform API
Hi Leo,

Thanks for reaching out. We do indeed support ean-8 barcodes, see our REST API documentation (https://platform.fatsecret.com/docs/v2/food.find_id_for_barcode) and further notes below.

You can also validate the using our free public API demo: https://platform.fatsecret.com/api-demo#barcode-api

If there are any particular barcodes not working for you, please provide them to our team via Contact Us here: https://platform.fatsecret.com/contact


To scan an EAN-8 barcode using the FatSecret Platform API, you must use the food.find_id_for_barcode method.

Important Prerequisite: This specific method is a Premier-only feature. If you are on the standard "Basic" (Free) plan, you will likely receive a "Missing scope" (Error 14) response. To use this, you need a paid Premier plan or the "Premier Free" tier (available for eligible startups and non-profits).

1. Format the Barcode (EAN-8 to GTIN-13)

The FatSecret API expects all barcodes to be in GTIN-13 format.

  • EAN-8 has 8 digits.

  • GTIN-13 has 13 digits.

  • Conversion: You must pad the EAN-8 code with 5 leading zeros.

Example:

  • Your EAN-8: 12345670

  • API Input: 0000012345670

2. The API Method

You will use the food.find_id_for_barcode method. There are two versions:

  • v1: Returns only the food_id. (You must then make a second call to food.get to see nutrition info).

  • v2 (Recommended): Returns the food_id and detailed nutritional information in one call.

Endpoint parameters:

  • method: food.find_id_for_barcode

  • barcode: The 13-digit padded string.

  • format: json (recommended).

  • region: (Optional but recommended, e.g., US, GB, AU) to get the correct product for your country.

Kind regards,
The fatsecret Platform API team

Leo Perez

unread,
Dec 1, 2025, 10:00:06 PM (10 days ago) Dec 1
to fatsecret Platform API
Hi Seba,

I have everything set up as you listed out, and I am a premier free member. 
It seems to work on a lot of the UPC-12 products around my home, but I went ahead and sent in a ticket to that contact link you sent with the barcodes I was testing:

(I formatted them here)
0051022500184
0000008067308
0000002101402
0000007096990

They are pretty common UPC-8 items, so I was thrown off by why it's not working with the barcode scanner or your API Demo search, but maybe you guys can help out. 

Thanks!

seba...@fatsecret.com

unread,
Dec 1, 2025, 10:10:33 PM (10 days ago) Dec 1
to fatsecret Platform API
Thanks Leo.
You need to input the full 13 digit Standard UPC code and 2 of those 4 will show, see screenshots attached. Hence you have to convert the UPC-E first, see brief AI generated guide attached below. You can ask your favourite LLM to write you a script.
We will add the other 2 currently not published items.

To convert a UPC-E barcode to the standard 12-digit UPC-A (and the 13-digit version often used in database lookup), you have to expand the compressed middle section.

Here is the step-by-step breakdown for your specific barcode: 07096990.

1. The Anatomy of your UPC-E

First, strip off the first and last digits to reveal the compressed 6-digit code.

  • System Character (Start): 0

  • Compressed Content (Middle): 709699

  • Check Digit (End): 0

The logic for expansion depends entirely on the last digit of that 6-digit middle section. In your case, the content is 709699, so the deciding digit is 9.

2. The Conversion Rule (For Ending Digit 5-9)

Because your code ends in a 9, it follows the simplest rule:

  • Manufacturer ID: Take the first 5 digits of the content.

  • Product ID: The number 0000 followed by that last digit.

3. Applying the Rule to 07096990


Step

Action

Result

1

Identify the 6-digit content

709699

2

Separate the last digit (Mode)

70969 (Data) & 9 (Mode)

3

Manufacturer Part: Use the data (first 5 digits)

70969

4

Product Part: Add 0000 + Mode digit

00009

5

Combine Manufacturer + Product

7096900009

6

Add back the Start (0) and Check (0) digits

070969000090

The Final Result:

  • UPC-A (Standard 12-digit): 070969000090

  • EAN-13 (Standard 13-digit): 0070969000090 (Just add a leading zero)


Reference: General Expansion Rules

If you need to convert other UPC-E codes, look at that 6th digit of the compressed section and apply the corresponding rule below.

(Let's assume the 6-digit content is represented as abcdeM, where M is the last digit)

  • If M is 0, 1, or 2:

    • Group: ab + M + 0000 + cde

    • Example: 210140 => 210000014

  • If M is 3:

    • Group: abc + 00000 + de

    • Example: 123453 =>  1230000045

  • If M is 4:

    • Group: abcd + 00000 + e

    • Example: 123454 => 1234000005

  • If M is 5, 6, 7, 8, or 9 (Your Case):

    • Group: abcde + 0000 + M

    • Example: 709699 => 7096900009

Screenshot 2025-12-02 at 14.06.11.png
Screenshot 2025-12-02 at 14.05.24.png

Leo Perez

unread,
Dec 1, 2025, 11:00:51 PM (10 days ago) Dec 1
to fatsecret Platform API
Awesome, thank you, Seba, for the quick reply and useful information!

I see where I went wrong, didn't take into account the UPC-E instead just thought they were EAN-8.

For any future food items that I find that after testing I know aren't in your Database, should I just collect them and then eventually send them in to you guys to get added?

seba...@fatsecret.com

unread,
Dec 1, 2025, 11:02:45 PM (10 days ago) Dec 1
to fatsecret Platform API
Hi Leo,
Thanks, yes please. I just sent you an email individually.
Kind regards,
The fatsecret Platform API Team

Reply all
Reply to author
Forward
0 new messages