Improve Your Running with Nike Run API & ChatGPT

Yongjoon Kim
7 min readSep 4, 2023

--

How to Become a Data-driven Runner

As some of you reading this might know, I’m a casual runner. I don’t do hardcore 20 km a day running, but I try to run 3–5 km/day in most of the days in a week. I’ve been doing this since my college days and it’s been always a way of staying healthy, getting away from daily stresses, and refreshing my mind by sweating out. I employed zero technology when I started to run, but started to use Nike Run app to keep logging my running history since late 2019. There was no grandiose goal to achieve with this, I simply wanted to see some numbers piling up as I run more and more. And then the COVID pandemic happened in early 2020… Running with Nike Run quickly became a way of keeping myself sane in my 200 sq.ft. studio apartment.

Nike Run iOS App

I liked the simplicity of the app– It checks how many kilometers (or miles) I run at each time, the pace of the run, total calories I burned, etc. But again, I had no idea about what to do with this data back then. I didn’t really utilize the data to take any action on my running habit. It was a non-actionable data. But after 4 years of using the app, I finally started to want to dig deeper into the data. It all seemed to make sense to be more data-driven about my own life and hobby especially after having transitioned into a more technology career path since 4–5 years ago. Why not using data for my own life and health as well as for my job?

Another inspiration was ChatGPT, especially its recently release Advanced Data Analysis plugin. (They used to call it ‘Code Interpreter’ and still calling it the same in their official documentation, I like the new name.) It’s a feature OpenAI has released in their GPT4 module, which allows you to upload any raw dataset like CSV or JSON format and ask for any tasks using the data such as data cleansing and analysis. After using it a few times in my daily job, I thought I could give this ‘AI data analyst’ a more fun stuff to do.

So I decided to do a really quick weekend project to scrape all my running data from Nike Run app and ask ChatGPT to analyze the data using the Advanced Data Analysis. Let’s dive into the “How.”

1. Get activity data from Nike Run API

So first thing first, I needed all my running data from Nike Run app. Unfortunately, Nike doesn’t have a proper open API documentations that allow developers to access data in their applications as of now. But fortunately, it seems that they used to provide developers with open API endpoints in the past and it is still available. I found some of the fellow data nerds tried to play with this in the past (credit to this Medium post 🙏) and was able to get the endpoint that I needed. Plus, I found a hacky way to get the authorization token as well. (if you work at Nike’s engineering team, a small security alert for you!) After quickly testing it with my Postman, everything seemed to be ready to roll.

A small cathartic moment when I get raw data from API

2. Organize the data

The result data includes all ‘activities’ that I’ve made in the app. Each activity refers to a single running session and it contains interesting data such as,

  • Started time & Ended time
  • Total duration
  • Session breakdowns
  • Run pace
  • Total distance
  • Run speed
  • Total calories burned
  • Weather of the day
  • Geocode of the running route

All these things looked really cool to me. There is so much intelligence I could get from this data about my own performance and habit. But there was one more thing left to do before analyzing it. Like many other APIs, there was a limit in the number of activities I can get from a single API request. Therefore, I wrote a simple python script that combines all the paginated data into a single JSON file.

import requests
import json

combined_data = {}

BASE_URL_01 = "https://api.nike.com/sport/v3/me/activities/after_time/{}"
BASE_URL_02 = "https://api.nike.com/sport/v3/me/activities/after_id/{}"
API_KEY = # Your Nike API token
HEADERS = {
"Authorization": "Bearer {}".format(API_KEY)
}

# Fetch the first result group
response = requests.get(BASE_URL_01.format("0"), headers=HEADERS)
first_result = response.json()
combined_data["activities"] = first_result["activities"]

# Function to fetch data recursively using the first result group
def fetch_data_recursively(after_id=""):
"""Fetch data from the API endpoint and calls itself recursively if there's an 'after_id' in the response."""
url = BASE_URL_02.format(after_id)
response = requests.get(url, headers=HEADERS)

if response.status_code != 200:
print(
f"Error fetching data with after_id: {after_id}. Status code: {response.status_code}"
)
return

data = response.json()
combined_data["activities"] += data["activities"]

next_after_id = data.get("paging", {}).get("after_id")

if next_after_id:
fetch_data_recursively(next_after_id)


# Initiate the recursive fetching
fetch_data_recursively(first_result["paging"]["after_id"])

# Save the result as JSON file
with open("total_run_data.json", "w") as file:
json.dump(combined_data, file)

3. Analyze it with Advanced Data Analysis

With the extracted JSON file in the previous step, we’re now ready to bring this to ChatGPT’s Advanced Data Analysis plugin and ask a bunch of questions. All you need to do is just 2 things: Simply upload your dataset to the plugin, and start asking analytical questions. ChatGPT will try to understand the structure of the source data first, clarify my analytical goal, and start analyzing the data by using python and well-established data analysis libraries like Pandas or Numpy.

ChatGPT’s Advanced Data Analysis plugin

As a result, I was able to get several interesting data visualizations with about 10 minutes of work. Here are the few examples of what I asked and what I learned from the analysis:

In which month did I run the most?

I was clearly running a lot during the pandemic between 2020 and early 2021. But I can see I ran less during the period when I had a gym membership 😅

How long & fast do I usually run? (Distance & pace)

It’s pretty obvious that I usually run around 5km per each session with 5–6 min/km pace. It makes me wonder if I should run a longer distance or faster.

How has my average pace changed over time?

It seems like my running pace has been way too consistent, or getting even slower in the past 12 months. Maybe I became too stagnant. In order to improve my performance, I think I need to increase my pace a little bit, hoping to see the graph go below 5 min/km in 3 months.

When do I usually run? (Morning / Afternoon / Evening)

I probably don’t even need this data to be visualized since I know it really well. I’m a night runner. Then a question arises: Does running in the evening help my running pace?

Is there any correlation between run pace and when I run?

It looks like whether I run in the evening or afternoon doesn’t really affect my running pace.

Conclusion: Be the Owner of Your Data

What I demonstrated above is just a quick glimpse of what you can do with a dataset you want to analyze and a little bit of help from ChatGPT. It gave me a huge confidence in being more data-driven in what I do in my personal life, as well as my professional life. Personally, knowing how to interact with web APIs and play with the data programmatically is the most impactful skillset that I have learned in the past 4–5 years. And whenever I find myself being able to work with this data and get actionable insights, I feel empowered. The tradeoff is that we live this life of ‘being tracked everywhere’ with all these mobile devices and apps we have, but if it’s inevitable, I want to take advantage of it instead of just giving it away to the Tech Big Brothers.

Data is so powerful only when you know how to use it.

--

--

Yongjoon Kim

Product manager & designer of built environment. Currently @cotta.ge