Source

Extracting Data from Nike Run Club & Visualizing It

Hi lovely people! 👋 Most people who know me in person know that I love running. I try to run at least twice a week. I properly started running in May 2017 and have been running more or less consistently since then. I have been using the Nike Run Club app to log all of my run data. When I started using it I had no idea that I was getting sucked into a walled garden and there was no official way to move my data out of the Nike ecosystem.

Now we know that the app loads data from the server so this means that there is definitely a remote API endpoint which we can access to get raw data. While I was trying to reverse engineer the NRC app to allow sniffing of SSL traffic, I came across a GitHub gist which contained NikePlus API description.

The author of that gist has put up a bash script which you can use to download all of your data from the Nike ecosystem and save it locally in json files.

Now the tricky part is that the endpoint requires Authorization Bearer token which we don’t already know. As it turns out the online Nike website also uses the same authentication backend and uses the same Authorization token as the Nike app. So all we have to do is go to the NikePlus membership website and open the developer tools. With the developer tools open, log in to your same Nike account which you use with the mobile app.

Now search for a request to api.nike.com and scroll down to the request headers. You should be able to see the Authorization header.

Nike Website

Copy the Bearer token and pass that as an input to the bash script.

The steps to run the bash script are as follows:

  • Download and save the script as nike_activities.bash on Desktop
  • Open the terminal and type:
chmod u+x ~/Desktop/nike_activities.bash
  • Run the script using the terminal (replace <bearer_token> with your actual token):
~/Desktop/nike_activities.bash <bearer_token>

Bash Script Nike

The bash script will download your data in activity-* files in the folder from where you run the script.

I used my data and some Jupyter Notebook and plot.ly magic to create this interactive graph. It contains my run data from since I began running.

styled-line

I hope you guys liked the post. I will try to write up a small tutorial for the Python Tips blog where I will explain how I parsed the JSON files and made this small plot.

In the meantime, I hope you all have a wonderful day/night. I will see you in the next article! ❤️ 😊

Newsletter

×

If you liked what you read then I am sure you will enjoy a newsletter of the content I create. I send it out every other month. It contains new stuff that I make, links I find interesting on the web, and occasional discount coupons for my book. Join the 5000+ other people who receive my newsletter:

I send out the newsletter once every other month. No spam, I promise + you can unsubscribe at anytime

✍️ Comments

Maria

Thanks a lot for sharing this!! It worked for me. Have you uploaded that python code anywhere?

Yasoob
In reply to Maria

Sorry Maria, I haven’t uploaded the code for visualization anywhere. It was spaghetti code 😅

JOe
In reply to Maria

Thank You for posting, looking forward to trying it out.

zinee

WOW! This is what I looking for! Thank you so much for sharing. I am a developer in South Korea who loves running. I hope you enjoy running without injury. :)

Taylor

Yasoob does the data also contain the routes you ran? I’m looking to make a personal heat map of the roads I have run in my city

Yasoob
In reply to Taylor

Hi Taylor,

I just took a look at the file and it does contain latitude and longitude data in there with timestamps :)

Sean

Hi Yasoob,

Thank you for describing how to extract Nike data. Very informative. Now I’m wondering if there is a person who uses TrainAsONE (www.trainasone.com) and is a programmer who could build something to take the extracted Nike data to be able to upload there….

Thanks again

Yasoob
In reply to Sean

Hi Sean,

Thank you so much for the comment. I wish I had any experience with the app you mentioned but sadly I have never used it before. But it’s a small world full of curious programmers so just wait and I am sure someone will come up with a solution :)

Have a good day!

David Weinstein

i got the following error {“error_id”:“5a1083ab-3b7a-4cfb-8e85-79a700fd856a”,“errors”:[{“code”:35,“message”:“Unauthorized user access”}]}

Yasoob
In reply to David Weinstein

Hi David!

Did you try going through the steps again? I tried them and it still works.

JB
In reply to David Weinstein

I receive the same error when I try to run this code in Python3: ‘{“error_id”:“a4f7e2d8-6c5e-4f98-8964-c00cd96fb5d3”,“errors”:[{“code”:35,“message”:“Unauthorized user access”}]}’

I am most likely not setting up something correctly.

import pycurl import certifi from io import BytesIO

buffer = BytesIO() header = [‘Authorization’, ‘Bearer eyJhbGciOiJSUzI……..'] url = ‘https://api.nike.com/sport/v3/me/activities/after_time/0'

c = pycurl.Curl() c.setopt(c.CAINFO, certifi.where()) c.setopt(c.URL, url) c.setopt(c.HTTPHEADER, header)
c.setopt(c.WRITEDATA, buffer)

c.perform() c.close()

body = buffer.getvalue() print(body)

Yasoob
In reply to David Weinstein

Hey David,

I just published this project on GitHub: https://github.com/yasoob/nrc-exporter Try using that and if the problem persists let me know :)

Say something

Send me an email when someone comments on this post.

Thank you!

Your comment has been submitted and will be published once it has been approved. 😊

OK