Withings to Garmin Connect – resurrection

After dropping “legacy” APIs on Withings page, the script stopped to work…

It took quite a while to adjust it to OAuth2 but finally – it’s done!

Go to https://github.com/jaroslawhartman/withings-sync to download the script.

References

  • Based on withings-garmin by Masayuki Hamasaki, improved to support SSO authorization in Garmin Connect 2.
  • SSO authorization derived from https://github.com/cpfair/tapiriik

Pre-requisites

$ sudo easy_install requests
  • simplejson
$ sudo easy_install simplejson

Usage

Usage: $python sync.py [options]

Options:
  -h, --help            show this help message and exit
  --garmin-username=<user>, --gu=<user>
                        username to login Garmin Connect.
  --garmin-password=<pass>, --gp=<pass>
                        password to login Garmin Connect.
  -f <date>, --fromdate=<date>
  -t <date>, --todate=<date>
  --no-upload           Won't upload to Garmin Connect and output binary-
                        string to stdout.
  -v, --verbose         Run verbosely

Obtaining Withings Authorization Code

When running for a very first time, you need to obtain Withings authorization:

$ ./sync.py -f 2019-01-25 -v
Can't read config file config/withings_user.json
***************************************
*         W A R N I N G               *
***************************************

User interaction needed to get Authentification Code from Withings!

Open the following URL in your web browser and copy back the token. You will have *30 seconds* before the token expires. HURRY UP!
(This is one-time activity)

https://account.withings.com/oauth2_user/authorize2?response_type=code&client_id=183e03e1f363110b3551f96765c98c10e8f1aa647a37067a1cb64bbbaf491626&state=OK&scope=user.metrics&redirect_uri=https://wieloryb.uk.to/withings/withings.html&

Token : _

You need to visit the URL listed by the script and then – copy Authentification Code back to the prompt.

This is one-time activity and it will not be needed to repeat.

Tips

You can hardcode your usernames and passwords in the script (sync.py):

GARMIN_USERNAME = ''
GARMIN_PASSWORD = ''

For advanced users – registering own Withings application

The script has been registered as a Withings application and got assigned Client ID and Consumer Secret. If you wish to create your own application – feel free!

Note, registering it is quite cumbersome, as you need to have a callback URL and an Icon. Anyway, when done, you should have the following identifiers:

IdentfierExample
Client ID183e03.................765c98c10e8f1aa647a37067a1......baf491626
Consumer Secreta75d65.................4c16719ef7bd69fa7c5d3fd0ea......ed48f1765
Callback URIhttps://jhartman.pl/withings/notify

Configure them in config/withings_app.json, for example:

{
    "callback_url": "https://wieloryb.uk.to/withings/withings.html",
    "client_id": "183e0******0b3551f96765c98c1******b64bbbaf491626",
    "consumer_secret": "a75d65******1df1514c16719ef7bd69fa7*****2e2b0ed48f1765"
}
Withings to Garmin Connect – resurrection
Tagged on:         

11 thoughts on “Withings to Garmin Connect – resurrection

  • 2019-02-26 at 13:36
    Permalink

    I am so happy I found this! It works perfectly thank you very much! I am moving slowly from withings to garmin and this is excellent to be able to incorporate withings scale to garmin connect.

    Do you think, it would be possible to connect the blood pressure measurements? Or maybe Garmin doesn’t have that information in their dashboards.

    Anyway thanks a lot!

    Reply
    • 2019-02-26 at 13:52
      Permalink

      Hi Richard,

      I’m glad you found this tool useful!

      I’m not aware of any option for Blood Pressure measurements in Garmin. I’m referring mainly to this link in Garmin forum.

      Best regards,
      Jarek

      Reply
  • 2019-12-06 at 19:51
    Permalink

    Thank you so much for your work on this script, and for making it available!

    I’m running into one issue that I can’t seem to make sense of. I got the script up and running, and have it scheduled to run every morning with the “from” date using a simple variable to just upload starting from the previous day, so it doesn’t do a full-sync from a set date, constantly making it take longer.

    However, only a single day seems to be syncing all the data available from withings, with every other day only seeming to sync weight.

    Any ideas or logs I should be looking at?

    Reply
  • 2019-12-08 at 17:36
    Permalink

    Hi Erik,

    Can’t really figure out what could be the problem. Can you give an example of command you use, best with `-verbose` and the output you’re seeing, something like:

    “`
    jhartman@wieloryb:~/scripts/withings-garmin-v2$ ./sync.py –fromdate ‘2019-12-07’ –verbose
    Withings: Refresh Access Token
    Withings: Get Measurements
    Measurements received
    generating fit file…
    appending weight scale record… 2019-12-08 17:33:47 81.19kg None%
    JaHa.WAW.PL
    Garmin Connect User Name: JaHa.WAW.PL
    attempting to upload fit file…
    Fit file uploaded to Garmin Connect
    “`

    Reply
    • 2019-12-08 at 20:05
      Permalink

      C:\withings-garmin-v2>python sync.py -f 20191201 -v
      Withings: Refresh Access Token
      Withings: Get Measurements
      Measurements received
      generating fit file…
      appending weight scale record… 2019-12-08 09:26:37 89.398kg 30.269000000000002%
      appending weight scale record… 2019-12-07 11:18:10 88.843kg 29.501%
      appending weight scale record… 2019-12-06 08:09:40 89.223kg 29.6%
      appending weight scale record… 2019-12-05 08:19:45 89.489kg 28.082%
      appending weight scale record… 2019-12-04 08:31:45 89.27kg 29.551000000000002%
      appending weight scale record… 2019-12-03 21:22:18 89.60000000000001kg 27.667%
      erik29gamer
      Garmin Connect User Name: erik29gamer
      attempting to upload fit file…
      Fit file uploaded to Garmin Connect

      Hi Jarek. This is everything I currently see. I’m currently running it on Windows since I’m a Windows admin and its where I spend most of my time, but I spun up an Ubuntu Server VM to verify that Windows wasn’t doing something weird with python and had no luck there either. After I noticed it not working, I uncommented the line in sync.py so that the .fit file is saved, and then tried manually uploading that to Garmin Connect and it has the same result.

      Additionally, I do have MyFitnessPal synced, so that may be where its currently getting the weight data from. In which case, the full sync still only worked once and has never worked since.

      Thanks for taking a look!

      Reply
      • 2019-12-08 at 20:41
        Permalink

        Hi Erik,

        However, only a single day seems to be syncing all the data available from withings, with every other day only seeming to sync weight.

        Somehow I think I still don’t understand the problem. Are you saying that despite setting -f it gets all you measurements even before the from-date (in your example: the 1st of December)?

        I’m speculating here, but if you want to get just a single day, you need to set -t as well, for example:

        jhartman@wieloryb:~/scripts/withings-garmin-v2$ ./sync.py --garmin-username=jaroslaw.hartman --garmin-password='VistaC2007!' -f 20191206 -t 20191206 -v
        Withings: Refresh Access Token
        Withings: Get Measurements
        Measurements received
        generating fit file...
        appending weight scale record... 2019-12-06 05:34:28 80.2kg None%
        JaHa.WAW.PL

        Best regards,
        Jarek

        Reply
        • 2019-12-08 at 21:04
          Permalink

          I have two batch files, one set to sync all data from one day beforehand that is set on a schedule. The other is set as a “full sync” from December 1st. I got my scale on the 3rd so it just set it for the beginning of the month. That snip was from running the “full sync”

          What is happening is that the first time I ran the script I set it for a single day (the 4th). It synced correctly and uploaded all the bone mass, fat percentage, etc. data to garmin. Since then it was either not synced any information, or only weight. I am unsure because I also have MFP linked which doesn’t have all the extra data and only syncs weight. I have removed the user json file, got a new token, re-setup in a new VM and it never actually uploads data to Garmin.

          I’m not great in Python, but I did temporarily edit the sync.py to write out the bone mass and hydration levels (instead of weight and fat ratio), so I know it is correctly getting the data from Withings.

          Reply
  • 2021-04-13 at 10:53
    Permalink

    hello,

    On 13/04/2021, is it still a working project ?

    should the sync be planned using cron ? or is it the case already ?

    Reply
  • 2021-07-05 at 17:35
    Permalink

    Hello Karen! Is it possible for you to guide a newbie through the setup? I bought a withings smart scale today and want it to sync with Garmin connect. What do I need to make it happen?

    Thanks☺️☺️

    Reply
  • 2022-04-14 at 10:30
    Permalink

    I am glad I found this page, thank you very much for your work!
    The GitHub page (https://github.com/jaroslawhartman/withings-sync) mentions three additional parameters “to-fit”, “to-json” and “output”, they do not work in 3.3.1 Are you planning to implement these or did I miss something?

    Reply

Leave a Reply to Erik Krause Cancel reply

Your email address will not be published. Required fields are marked *