openfoodfacts / openfoodfacts-dart

Open Food Facts API Wrapper
https://pub.dev/packages/openfoodfacts
Apache License 2.0
167 stars 67 forks source link

Add support for API v3 Product WRITE requests to add / edit packaging components #617

Closed stephanegigandet closed 1 year ago

stephanegigandet commented 2 years ago

The new API v3 to add/edit packaging components is almost finalized and implemented (but deployed only on the .dev server currently).

Server-side PR with the documentation and implementation: https://github.com/openfoodfacts/openfoodfacts-server/pull/7614

There could still be minor changes (in particular, it is likely that we will use PATCH requests instead of POST requests). I will update this bug when it is merged, deployed on .net and then on .org If you have feedback about the API, please let me know, we can still change things if needed.

Note that future v3 APIs will use the same model for reporting warnings and errors etc. so it would be good to have generic code for it. In particular, the API v3 for product READ is already implemented as well (with full v2 features support).

The API v3 product WRITE currently only supports packaging data, so we will need to keep the existing code for API v2 for some time.

stephanegigandet commented 1 year ago

Unfortunately my computer power cable crashed this morning.

@monsieurtanuki Sorry to hear that. :(

monsieurtanuki commented 1 year ago

@stephanegigandet I have a new cable now: I'm back ;)

stephanegigandet commented 1 year ago

@monsieurtanuki Wonderful :)

monsieurtanuki commented 1 year ago

@stephanegigandet Regarding api v3 and "get products" queries, in Smoothie we sometimes use "user" queries (e.g. "the products I contributed to"), and for that we use a different syntax.

Instead of /cgi/search.pl, we use

But it doesn't look like we can apply the api_version=3 parameter, which makes it impossible to retrieve packagings for user related search (which does not) - for text search it's OK as we saw.

stephanegigandet commented 1 year ago

@monsieurtanuki I also added recently a new field "packagings_complete" which takes values 0 or 1, to indicate if all the packaging components are listed: https://github.com/openfoodfacts/openfoodfacts-server/pull/7856/files

stephanegigandet commented 1 year ago

@monsieurtanuki for the "user" queries, I will need to implement /api/v3/search but there won't be server deployments until the first week of January.

There is a possible workaround:

https://world.openfoodfacts.org/cgi/search.pl?action=process&tagtype_0=editors&tag_contains_0=contains&tag_0=stephane&page_size=20&json=1&fields=code,packagings&api_version=3

It works for editors, photographers, informers

It doesn't work for contributor

monsieurtanuki commented 1 year ago

@stephanegigandet Actually I wouldn't call it a workaround but the solution! I like this "search.pl / tagtype_x" syntax: doing so we reuse the same query search pattern as most queries.

Of course, if it could work for "contributor" that would solve it all. For the moment I will make it work in off-dart for editors, photographers and informers.

monsieurtanuki commented 1 year ago

@stephanegigandet Actually there is probably a tag for "contributor": wouldn't it be creator?

And for "to be completed", I interpret that as "all the products I'm an informer for and with the state 'en:to-be-completed'".

Therefore I'm done here, just about to PR: I got the same counts with the old v2 (and "different" URI) and with the new v3 (all with the "standard" search.pl).