Fetching my Garmin wellness data

I had Garmin watches for years now. The last one is recording my “wellness data” (steps, heart rate) and publishing it to Garmin’s servers. While the Garmin Connect website is great I want to get a backup of these data on my own computer.

Garmin has a Health API, but requesting access requires a painful process. So, I decided to write my own script to fetch the data.

In this article I detail the process used and how I came to choose BASH and curl as the best technology.

When I first try to backup the data, I used Puppeteer. This is a NodeJS module that allows to drive Chromium from NodeJS. I used it to navigate to the Garmin Connect application, enter my login and password, then perform the data retrieval. However, the process is heavier than what it should be, and there is no Puppeteer version for my Raspberry Pi.

So I decided to switch to BASH and curl to make the script lighter and compatible with the ARM architecture. The process is a bit harder though. Using curl requires to mimic the browser behavior, especially while handling the form submission and cookies.

Authentication

The Garmin Connect authentication form is embedded inside an IFrame. Its URL is:

https://sso.garmin.com/sso/signin?…lots of arguments…

I did not managed to understand exactly how yet, but this ends with a SESSIONID parameter wrote to the cookie. I discovered that this is the only parameter that is really needed by the application to authenticate the user.

At this time, I’m not yet available to retrieve the SESSIONID using curl. This will force you to manually login and get the SESSIONID value form your cookie, for example using the “EditThisCookie” extension.

User “displayName”

I found that the user id, required in the URLs is defined in the HTML code returned for the main application. So in fact, the HTML loaded is personalized with some personal information exported as script.

Retrieving data

The Garmin Connect application has several HTTP routes that allow it to retrieve the necessary data to display the different charts and statistics. The routes are called as HTTP requests from the JavaScript and return data in JSON format which is exactly what I want.

I inspected the different pages and selected 5 routes that allow me to retrieve : the daily summary, the heart rate data, the steps data, the movements data and the list of activities. I believe that it should be possible to retrieve the full activities data but I am not interested by those data yet.

As mentioned earlier, you will require the user “displayName” to form the URL and the SESSIONID value from the cookie to retrieve the data.

Running the script

So I wrote a simple BASH script to perform the necessary curl requests to retrieve the user “displayName” and fetch the data in JSON format. The code is available below and on Github.

This are the instructions to prepare the required data and launch it:

  1. Open a browser and connect to the Garmin Connect website.
  2. Login into the application using your usual login and password.
  3. Retrieve the SESSIONID field from your cookie. Personally, I use the “EditThisCookie” extension for Google Chrome.
  4. Launch the script with the SESSIONID value as argument.
  5. The script will retrieve your data from yesterday to the MIN_DATE value in the script file.

The script

Conclusion

Writing the code was really funny, specially trying to understand the authentication process. I will continue to investigate and learn new things. Hopefully, I will be capable to figure out the whole authentication process and make a fully autonomous script in a near future.

12 Replies to “Fetching my Garmin wellness data”

  1. Very nice. Thanks for this. I tried, created the config.json. This seems to work. But when I enter the session id from Garmin Connect, I get

    Write a file 2d6654ec-d378-4e59-ab96-fdda98d402d5 containing: {“email”:”…”, “password”:”…”, “min_date”:”2018-01-01″}

    Could you help?

  2. Hi Markus, I updated the script but not the instructions. Now you won’t need to pass the SESSION_ID by yourself. Just write a config.json file and launch the script without any argument. This should be ok. I haven’t been running the script for a while though, so I hope there was no change in Garmin’s API.

  3. Hi Markus. I updated the script but not the instructions. In fact you don’t need to pass the SESSION_ID anymore. Just prepare the config.json file and run the script. If you don’t want the JSON file to be in the same folder as the script you can specify its path as first argument.

  4. Hi,

    I would love to know where you found the Garmin documentation for your implementation ! This blog article is very helpful to me. I am currently involved in a project in which I have to retrieve Garmin data from multiple persons. The Health API data is much coarser than the data I have found using your method. Maybe I have overlooked something, but I can’t find any Garmin specs of the portal you are using. Would appreciate an answer. Thanks in advance, and thanks for the article.

    cheers

    Cspr

  5. Hi,

    Thanks for your comment.

    There is no doc at all from Garmin documentation. I used Chrome’s debugging tool to inspect the API.
    Of course this implies that Garmin can change the specs at any time and things will be broken.

    Regards

  6. Hello,

    I am interested in being able to pull my data based on my login. I thought I would need an API key from Garmin to do so, but I stumbled across your script. When trying this on my own, I can’t seem to log in using my Garmin connect credentials. It seems to fail at generating/collecting a token in this check:

    TOKEN=`cat /tmp/token`
    if [[ “${TOKEN}” == “” ]]
    then
    echo -e “\033[31mfailed\033[0m”
    exit
    fi

    When viewing the html file in “/tmp/auth.html”, the contents are:

    “error code: 1015”

    Do you have any ideas/suggestions?

  7. Hi Pat,

    Thanks for your comment. The script is not working on my side anymore. I believe Garmin changed their login URL.

    I obtained the URL by opening the developer tools in Chrome (Press F12). Then I inspected the network traffic in the “Network” tab.
    Hope this can help. Sorry, but I can’t do more for now since I have very limited access to Internet. Fill free to post any update here, I update my post.

    Best regards

  8. Norton.com/setup – The digital world is communicated through the web , and it’s the main source of varied information circulated on the online . aside from this stuff , Internet is additionally the source of multiple viruses and online thefts. Norton is among the foremost

  9. This means that the user needs a secured web browsing system. this is often possible if you’re using the antivirus software McAfee.com. This software scans every website and blocks the access to the insecure and damaging websites of the browser. Users usually need support from McAfee certified experts who know the features of McAfee antivirus which will be applied without having to stress about it. it’s important to properly setup McAfee using mcafee com activate, install/reinstall and activate McAfee for the right functioning of the antivirus software.

  10. These tools can assist you complete various smallest and significant tasks and projects on your computer. If you do not have MS Office in your PC, get the Office setup from office.com/setup.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.