Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quantities in "mg" are returned in "g" from the API. product_quantity type changes based on unit. #11346

Open
theedov opened this issue Feb 8, 2025 · 3 comments

Comments

@theedov
Copy link

theedov commented Feb 8, 2025

What

Few issues:

  • 9344962003855: "product_quantity" is 175mg but API returns 0.75 with "g" unit. Also there's an issue with "product_quantity" type, if it's in grams, the type is string("175"), but when it's mg, the type is number(0.75).
  • 9310653105610: Also for web it seems that salt is entered in "mg", but is shown in "g". While calcium is entered in "mg" and is correctly shown in "mg".

Expected behavior

If entered in MG, API should return MG value, etc...

Screenshot/Mockup/Before-After

Image Image Image

Type of device

REST-API

Number of products impacted

See at least 1.

@github-project-automation github-project-automation bot moved this to To discuss and validate in 🍊 Open Food Facts Server issues Feb 8, 2025
@theedov theedov changed the title Macros in "mg" are returned as "g" value from the API Quantities in "mg" are returned in "g" from the API. product_quantity type changes based on unit. Feb 8, 2025
@stephanegigandet
Copy link
Contributor

Hi @theedov ,

The API converts all entered value in a default unit (g for most nutrients), and stores it in the _100g and _serving fields.
Then the client can convert it to other units as it decides. On the OFF website for instance, in Europe we display salt in grams, while we display it in mg for the US.

The type number / string issue is a long standing issue due to the Perl internals that convert types on the fly, we have not found a solution for that.

Same for product_quantity: it is always converted to g or to ml.

@stephanegigandet
Copy link
Contributor

@theedov
Copy link
Author

theedov commented Feb 12, 2025

@stephanegigandet Thank you for the explanation. Quick question, does API always return _100g values or there are scenarios when it's not there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To discuss and validate
Development

No branches or pull requests

3 participants