Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I'm trying get my activites from the strava API in a Fabric notebook. I've followed all the instructions and it works fine.
One issue I have is that I would like to automate getting data. What is holding me back is a code I need to get from the url I click on a authorize button from this website: strava.com/oauth/authorize?client_id=[CLIENT_ID]&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fcallba....
That brings me to a localhost callback page where I extract the code from the url and put in my code.
This is where I use the code..
training = requests.post(
'https://www.strava.com/oauth/token',
data = {
'client_id': client_id,
'client_secret': client_secret,
'code': code,
'grant_type': 'authorization_code'
}
)
Is there a way to to this action in a fabric notebook? From what I've seen is that trigger this, but would be so happy if anyone could help me.
Solved! Go to Solution.
Hi @pbi_taken,
Thank you for reaching out in Microsoft Community Forum.
Please follow below steps to Automating Strava API Data Access in Fabric Notebook
1.The code from the Strava OAuth flow is only needed once to retrieve the initial access_token and refresh_token. After that, you should use the refresh_token to keep getting new access_tokens without requiring the code again.
2.Replace grant_type = 'authorization_code' with grant_type = 'refresh_token' and call the token endpoint:
response = requests.post(
'https://www.strava.com/oauth/token',
data={
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
)
3.If you're getting 401 errors, check the access_token permissions. You must have activity:read_all scope granted during the initial authorization. If the token lacks required scopes, reauthorize manually with:
4.Add debugging for response.status_code and print response.json() to catch and understand errors:
if response.status_code != 200:
print("Error during token fetch:", response.status_code, response.json())
If the issue still persists,In this scenario we suggest you to raise a support ticket here. so, that they can assit you in addressing the issue you are facing. please follow below link on how to raise a support ticket:
How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn
Hi @pbi_taken,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Please continue using Microsoft community forum.
Thank you,
Pavan.
Hi @pbi_taken,
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, kindly "Accept as Solution" and give it a 'Kudos' so others can find it easily.
Thank you,
Pavan.
Hi @pbi_taken,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please "Accept as Solution" and give a 'Kudos' so other members can easily find it.
Thank you,
Pavan.
Hi @pbi_taken,
Thank you for reaching out in Microsoft Community Forum.
Use Strava’s refresh token flow to automate getting new access tokens — no need to manually get the authorization code every time.
Please follow below steps to resolve the issue;
1.Manually authorize once using the URL → get:
access_token
refresh_token
expires_at
2.In your Fabric notebook, use this refresh_token to automatically get a new access_token:
response = requests.post(
'https://www.strava.com/oauth/token',
data={
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
)
3.Use the new access_token to call Strava APIs.
Please continue using Microsoft community forum.
If you found this post helpful, please consider marking it as "Accept as Solution" and give it a 'Kudos'. if it was helpful. help other members find it more easily.
Regards,
Pavan.
Hi,
thanks! I've tried this now. just changing my code with what you suggested. Doesn't seem to work when converting it to a dataframe..
Any idea why?
My code is below..
response = requests.post(
'https://www.strava.com/oauth/token',
data={
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
)
token_response = response.json()
access_token = token_response['access_token']
headers_act = {
'Authorization': f'Bearer {access_token}'
}
training_response = requests.get('https://www.strava.com/api/v3/athlete/activities', headers=headers_act)
activities = training_response.json()
df_pd = pd.DataFrame(activities)
print(df_pd)
message errors
0 Authorization Error {'resource': 'AccessToken', 'field': 'activity...
Hi @pbi_taken,
Thank you for reaching out in Microsoft Community Forum.
Please follow below troubleshooting steps to resolve the error;
1.Print the response from the token refresh request to verify you're receiving a valid access_token. Use print(response.json()).
2.Make sure the refresh token is valid and hasn’t expired. If it's invalid, you'll need to go through the authorization flow again.
3.Make sure that the access_token has the necessary permissions (scopes) to access the Strava API endpoint, such as activity:read_all.
4.Add error handling to both the token refresh request and activities request to catch and print any errors, and check the status_code for any issues:
if response.status_code != 200:
print(f"Error: {response.status_code}")
print(response.json())
Please continue using Microsoft community forum.
If you found this post helpful, please consider marking it as "Accept as Solution" and give it a 'Kudos'. if it was helpful. help other members find it more easily.
Regards,
Pavan.
this url:
'strava.com/api/v3/athlete/activities'
which I need i requires both access_token and code, which is what I'm getting from the localhost url... This is what I'm getting without inputting code..
{"message":"Authorization Error","errors":[{"resource":"Athlete","field":"access_token","code":"invalid"}]}
from what i understand, there is no way of getting around that..
Hi @pbi_taken,
Thank you for reaching out in Microsoft Community Forum.
You do not need the original code again once you've received the refresh_token from the first manual authorization.
Please use the below steps to automate;
1.Use the refresh_token to get a new access_token:
response = requests.post(
'https://www.strava.com/oauth/token',
data={
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
)
2.Use only the access_token from that response to call Strava’s API:
headers = {'Authorization': f'Bearer {access_token}'}
requests.get('https://www.strava.com/api/v3/athlete/activities', headers=headers)
Please continue using Microsoft community forum.
If you found this post helpful, please consider marking it as "Accept as Solution" and give it a 'Kudos'. if it was helpful. help other members find it more easily.
Regards,
Pavan.
I really appreciate your help, but I still can't see a way around this..
according to strava documentation you need the code: Strava Developers.
trying what you suggested just results for me in a <Response [401]>..
Hmm really wish someone else has done this successfully in the past..
Hi @pbi_taken,
Thank you for reaching out in Microsoft Community Forum.
Please follow below steps to Automating Strava API Data Access in Fabric Notebook
1.The code from the Strava OAuth flow is only needed once to retrieve the initial access_token and refresh_token. After that, you should use the refresh_token to keep getting new access_tokens without requiring the code again.
2.Replace grant_type = 'authorization_code' with grant_type = 'refresh_token' and call the token endpoint:
response = requests.post(
'https://www.strava.com/oauth/token',
data={
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'refresh_token',
'refresh_token': refresh_token
}
)
3.If you're getting 401 errors, check the access_token permissions. You must have activity:read_all scope granted during the initial authorization. If the token lacks required scopes, reauthorize manually with:
4.Add debugging for response.status_code and print response.json() to catch and understand errors:
if response.status_code != 200:
print("Error during token fetch:", response.status_code, response.json())
If the issue still persists,In this scenario we suggest you to raise a support ticket here. so, that they can assit you in addressing the issue you are facing. please follow below link on how to raise a support ticket:
How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Fabric update to learn about new features.