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

wger (open source workout manager) weight sync support #683

Closed
gudvinr opened this issue Jan 10, 2021 · 12 comments
Closed

wger (open source workout manager) weight sync support #683

gudvinr opened this issue Jan 10, 2021 · 12 comments
Labels
enhancement Indicates new feature requests

Comments

@gudvinr
Copy link

gudvinr commented Jan 10, 2021

Is your feature request related to a problem? Please describe.
There aren't many open source health trackers but probably most known (or only existing) is wger which has REST API too.

Describe the solution you'd like
It would be useful to have wger support to sync along with google fit and mqtt.

Describe alternatives you've considered
Possible alternative is to support openscale MQTT protocol. But openScale is not a service from where you can "pull" the data but rather "push"-based client.
MQTT output which exists in sync is only useful for services you write yourself otherwise it isn't good practise to support multiple client APIs in single service.

Also there's no "standard" API specifications for this kind of thing so you already must implement healthkit/google fit integrations different.

Additional context

Here is the documentation for API.
You must know beforehand server endpoint (because, well, it is self-hosted) but you may use https://wger.de/api/v2/ as default one.

Before sending requests you must send POST /api/v2/login to obtain token using Content-Type: application/json with payload containing username and password. It is a bit unclear from documentation so I made an issue here.

After that you may send POST api/v2/weightentry/ using Authorization: Token and Content-Type: application/json with date and weight fields.

@oliexdev oliexdev added the enhancement Indicates new feature requests label Jan 11, 2021
@oliexdev
Copy link
Owner

I actually already played a bit around with the wger API, see wger-project/wger#448
But currently the DELETE and PATCH operation is not allowed, which prevent it to sync with openScale.

@gudvinr
Copy link
Author

gudvinr commented Jan 11, 2021

Thanks, good to know

@rolandgeider
Copy link

FYI that was only for some of the exercise related endpoints (we recently changed some of the DB structure and still need to make sure the submission process works), I should have been clearer there. The weight endpoint should have no problems with PATCH and DELETE (and if it does, just ping me)

@oliexdev
Copy link
Owner

@rolandgeider unfortunately, for me it still not work at https://wger.de/api/v2/weightentry/ there is no PATCH or DELETE operation allowed:

Allow:
GET, POST, HEAD, OPTIONS

But I might do something wrong? If I try to delete something, I always get this back as a response {"detail":"Method \"DELETE\" not allowed."}

@rolandgeider
Copy link

That is strange. Did you send the auth header? I'm developing a flutter app that talks to the server via the regular REST API and it definitely works

@oliexdev
Copy link
Owner

I used this command (XYZ is replaced with the correct token)

curl -X DELETE https://wger.de/api/v2/weightentry -H 'Authorization: Token XYZ' -d '{"date":"2020-12-04","weight":"77"}' -H "Content-type: application/json"

@rolandgeider
Copy link

It does look like a bug, that should work

@rolandgeider
Copy link

I have found what's wrong, hadn't seen it in the beginning. To PATCH a specific weight entry you'd use /v2/weightentry/<id>/, while '/v2/weightentry/' is for overviews and POSTing new ones.

@oliexdev
Copy link
Owner

oliexdev commented Feb 3, 2021

@rolandgeider thanks it works now 👍 sorry for the confusion

@oliexdev
Copy link
Owner

@rolandgeider I have implemented a first version for synchronization openScale sync with wger. It works good but I have two remarks:

  1. In the wger REST API you get/save the date in the yyyy-MM-dd format, which prevent you to add multiply weights for one day. I would suggest to get/save the date in msec or millisec (regarding to the Unix Epoch Time).
  2. You use in the REST API an id to identify the weight entry. Here it would be again better to use the date in msec/millisec for the identifier. Currently I need to fetch the whole wger weight entry list to search for the wger id to update or delete a wger weight entry.

Would you consider to change that in your REST API? If yes how fast could that be implemented in wger?

@rolandgeider
Copy link

Nice!!

Yes, there is also a uniqueness constraint in the model, so that only one entry per user and date can be saved. Adding more wouldn't make much sense for an app like wger and makes things like plotting the chart easier if there aren't duplicate entries.

And as for the ID, you can search if there are entries for a specific date with /api/v2/weightentry/?date=2021-02-21

@oliexdev
Copy link
Owner

@rolandgeider thanks for the hint with the date query, I use this instead of fetching all data. I have been released the openScale sync 0.3.2 , which should support the synchronization with wger. Thanks for your open-source workout manager. 🏅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

No branches or pull requests

3 participants