Fetching Garmin data, done !

In my previous article, I managed to fetch Garmin Connect wellness data as JSON but I needed to fetch the authentication SESSIONID using a browser. It appears that login into the application was not so complicated. I managed to understand how to perform the authentication on Garmin Connect using BASH and curl. So now, my script is fully autonomous.

EDIT: The project now has its own repository on Github.

Garmin Health API

As I mentioned in my previous post, Garmin has an health API that requires a special registration. So I took my chance and applied. I rapidly received a mail telling me that my request was rejected due to the fact that the API is reserved to professional use. Of course, I understand Garmin’s position, but I hope that they will change their strategy in the future.

The mail also focused on the possibility to download the data from the Garmin Connect application in reports. However, since it cannot be automated, this still justifies the need for my script.

Authentication using curl

Authentication on the Garmin Connect website is done in two steps. First we need to send the login and password to the SSO. It replies with an HTML page containing some JavaScript sending an XHR to the server in order to retrieve the cookie with the SESSIONID field. The problem was to “parse” the HTML and retrieve the URL.

Once the URL is retrieve, we just need to access the URL and retrieve the cookie. Since curl has some special option to save the cookies in a “cookiejar”, it is simple. Finally I parsed the cookiejar to read the SESSIONID field and that’s it.

What comes next

So I managed to retrieve all of my data, and I can now use a cron to automatically retrieve new data. I also made some scripts that use jq to process the JSON files retrieved and send the data to InfluxDB so I can see my stats in Grafana.

The last things that needs to be done is to have a mechanism that will automatically check the retrieved JSON files in order to prevent sending wrong data. In fact, the actual version of the script won’t re-download the data once the file is wrote, even if it contains incomplete data or errors.

A special note to Garmin

I’m just a nerd wanting to backup and see is own data in Grafana. This has no special interest, except keeping me busy during holidays and training me to curl + BASH. I really love the quality of your products, and I’m not willing to make you any prejudice.

The script

Below is the script. The authentication information (email + password) are stored in a separated file in JSON format. The script requires the jq application to read it. The config has the following format:

  "email": "...",
  "password": "...",
  "min_date": "yyyy-mm-dd"

The script fetches data from yesterday (yes since the day is not finished) to the min_date field included. All the files are stored in a data folder that you will need to create. If the file already exists it won’t be overwrote.

2 Replies to “Fetching Garmin data, done !”

  1. Bonjour,

    Pourrais-tu faire un article sur comment tu exploites tes données Garmin avec InfluxDB et Grafana ?
    Obtiens-tu des données qui tu ne peux pas avoir/visualiser via Garmin Connect ?

  2. En fait l’objectif était juste de garder une copie des données chez moi. Je n’ai pas vraiment fait de graphique spécifique avec.

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.