Get GPX

294 views
Skip to first unread message

Luke Fusion

unread,
Aug 30, 2021, 5:51:43 PM8/30/21
to Strava API


Hi,
how to get GPX file from some activity?
I'm using succesfully my client id and client secret for GPX upload but GPX download not works.


Something like

`curl -G "https://www.strava.com/api/v3/activities/$activity_id/streams/latlng,altitude,time" -H "Authorization: Bearer $strava_access_token" --output ...`
returns this error:
`{"message":"Resource Not Found","errors":[{"resource":"Activity","field":"","code":"not found"}]}`


Do you know why?

Walker Sutton

unread,
Sep 18, 2021, 10:56:36 PM9/18/21
to Strava API
Hi Luke,

Firstly, it looks like your request URL may be malformed. According to the documentation, your URL should look something like:
https://www.strava.com/api/v3/activities/{id}/streams/?keys=latlng,altitude,time&key_by_type=true

Also, I thinkkk the error message you're getting with the {... "code": "not found" ...} means that your `$strava_access_token` is no longer valid, so you might want to try refreshing it.

Let me know if that helps,

Walker

Luke Fusion

unread,
Sep 19, 2021, 8:54:20 AM9/19/21
to Strava API
Hi, I tested it. $strava_access_token is valid - for example for get activity id: curl -G https://www.strava.com/api/v3/uploads/$strava_upload_id -H "Authorization: Bearer $strava_access_token"

So I tried to tested with changed url:
curl -G "https://www.strava.com/api/v3/activities/$activity_id/streams/?keys=latlng,altitude,time&key_by_type=true" -H "Authorization: Bearer $strava_access_token"
But result is similar: {"message":"Record Not Found","errors":[{"resource":"Activity","field":"id","code":"invalid"}]}

Variable $activity_id contains id of activity which I know from https://www.strava.com/api/v3/uploads/$strava_upload_id.
Dne neděle 19. září 2021 v 4:56:36 UTC+2 uživatel walker....@gmail.com napsal:

kingo...@gmail.com

unread,
Sep 19, 2021, 9:40:42 AM9/19/21
to Strava API
Are you accounting for the fact that an upload ID and an activity ID are totally different?

Luke Fusion

unread,
Sep 19, 2021, 9:45:44 AM9/19/21
to Strava API
Yes, they're different. Upload_id is 636*******, activity_id is 598*******.
Dne neděle 19. září 2021 v 15:40:42 UTC+2 uživatel kingo...@gmail.com napsal:

Walker Sutton

unread,
Sep 19, 2021, 1:03:04 PM9/19/21
to Strava API
Maybe there's a permission error? What scope does this user have (activity:read, activity:read_all, etc.)? Is this activity private?
I would try testing that endpoint with a few different activity_id values; maybe test activity_id values that were created with different applications (API, Strava App, etc.)

Luke Fusion

unread,
Sep 19, 2021, 2:11:10 PM9/19/21
to Strava API
I'm using this permission: activity:write,read_all. Activity is for followers. But I tried it with public activity too.

I tried to record some activity with Strava app (saved as public) and download GPX. The same result: {"message":"Resource Not Found","errors":[{"resource":"Activity","field":"","code":"not found"}]}


Dne neděle 19. září 2021 v 19:03:04 UTC+2 uživatel walker....@gmail.com napsal:

Walker Sutton

unread,
Sep 20, 2021, 12:28:04 AM9/20/21
to Strava API
Hi Luke,

I just managed to get a good response from the getUploadById endpoint.
I used Postman with my access_token set as a Bearer Token, and the request URL looks like this:
https://www.strava.com/api/v3/uploads/<value passed as 'external_id' in createUpload call> (my external_id value happens to be an integer)

Also, make sure you're sending a GET and not a POST.

Any luck this time?

Walker
Message has been deleted
Message has been deleted

Luke Fusion

unread,
Sep 20, 2021, 2:26:20 AM9/20/21
to Strava API
HI, thanks!
I'm sending a GET request.

Example:
curl -G https://www.strava.com/api/v3/uploads/6361234567 -H "Authorization: Bearer 1a2b3c4d5e6f"
{"id":6361234567,"id_str":"6361234567","external_id":"12345.gpx","error":null,"status":"Your activity is ready.","activity_id":5985432101}

I tried this after that:
curl -G "https://www.strava.com/api/v3/activities/(6361234567 or 5985432101)/streams/?keys=latlng,altitude,time&key_by_type=true" -H "Authorization: Bearer 1a2b3c4d5e6f"
Result: {"message":"Resource Not Found","errors":[{"resource":"Activity","field":"","code":"not found"}]}

"external_id" is "12345.gpx" - but this is not integer and Strava APi says: "resource":"resource","field":"path","code":"invalid"

I'm doing some mistake somewhere but I don't know where.

Dne pondělí 20. září 2021 v 6:28:04 UTC+2 uživatel walker....@gmail.com napsal:

Walker Sutton

unread,
Sep 20, 2021, 10:14:19 AM9/20/21
to Strava API
Ahh! I understand your problem now.

Try this:
1. Send your POST to /uploads (uploadActivity). You should receive a response similar to this:
{'id': 6367599499, 'id_str': '6367599499', 'external_id': None, 'error': None, 'status': 'Your activity is still being processed.', 'activity_id': None}
2. take the 'id' from the POST response and pass it in as your uploadID in your GetUpload call (/uploads/6367599499)
In this response, I've been able to get a valid activity_id. You can verify that this response matches your original upload by observing the external_id property here and checking against the external_id you passed in for your uploadActivity call.

This should work!
*crossing my fingers*

Walker

Luke Fusion

unread,
Sep 20, 2021, 3:36:56 PM9/20/21
to Strava API
POST request? Are you sure?
I see "Record Not Found" when I send POST request. I see correct reply only when I send GET request. I'm confused.


Dne pondělí 20. září 2021 v 16:14:19 UTC+2 uživatel walker....@gmail.com napsal:

Walker Sutton

unread,
Sep 20, 2021, 5:45:43 PM9/20/21
to Strava API
Sorry, that may've been confusing. These visuals might be better: 

1. Uploading a new GPX activity
1. POST - createUpload.png
2. Getting the status of the uploaded activity
2. GET - getUpload.png
3. Observing the activity obtained in the above GET request is valid
3. Observe activity_id is valid.png
4. Ensuring I can use this activity_id not only on the website, but also to request data about the activity
4. GET getActivity.png
5. Getting stream data
5. GET getActivityStreams.png

Luke Fusion

unread,
Sep 21, 2021, 5:03:12 AM9/21/21
to Strava API
Thanks for images!

I'm trying it still the same as you. My activity request (streams?keys=latlng,altitude,time&key_by_type=true) ends with this error: {"message":"Resource Not Found","errors":[{"resource":"Activity","field":"","code":"not found"}]}

I see where is the problem maybe. I'm sending this scope in my app: .appendQueryParameter("scope", "activity:write,read_all")
But I see only scope: read  at the webpage https://www.strava.com/settings/api (maybe old authorization?).

I'll going to the mountain bike afternoon. Afterthat I'll try to authorize to the Strava again and I'll test it. There must be somewhere problem and I don't see it. I'll write here. Thanks again!





Dne pondělí 20. září 2021 v 23:45:43 UTC+2 uživatel walker....@gmail.com napsal:

Luke Fusion

unread,
Sep 21, 2021, 5:15:50 AM9/21/21
to Strava API
Hmm, validity of access_token is extended but I still see scope: read. What scope do you see at the webpage https://www.strava.com/settings/api?

Dne úterý 21. září 2021 v 11:03:12 UTC+2 uživatel Luke Fusion napsal:

Walker Sutton

unread,
Sep 21, 2021, 8:13:40 AM9/21/21
to Strava API
I'm not testing against my primary Strava account, so on the strava/com/settings/api page, the scope is 'read', but making a call to getActivityStreams shouldn't require write permissions, so I wouldn't think that's your issue.

Luke Fusion

unread,
Sep 21, 2021, 11:01:04 AM9/21/21
to Strava API
I need write permission because I upload activities from my app. I wanna download GPX for check altitude and so on. Nothing important but it's weird - this is the reason why I want to solve it.
I tried to download GPX from your activity too (5992678059) - and again: {"message":"Record Not Found","errors":[{"resource":"Activity","field":"id","code":"invalid"}]} 🤪

Dne úterý 21. září 2021 v 14:13:40 UTC+2 uživatel walker....@gmail.com napsal:

Walker Sutton

unread,
Sep 21, 2021, 12:38:45 PM9/21/21
to Strava API
Is your code publicly available? Do you have a link to GitHub or something similar?

kingo...@gmail.com

unread,
Sep 21, 2021, 1:03:43 PM9/21/21
to Strava API
This is not the same error as you reported previously. This one specifies the "id" field as invalid.

You cannot use the API to access the activity of a user that has not authorised your app. This is regardless of the privacy setting of that activity. So unless Walker has authorised your app to access their activities this _new_ error seems reasonable.

Have you tried requesting the scope "activity:read_all" when trying to access your uploaded activity? This is not the same as "read_all" or "activity:write".
Message has been deleted

Luke Fusion

unread,
Sep 21, 2021, 4:15:49 PM9/21/21
to Strava API
Ooooooooooooo, I got it!
I did small code change of "scope"
Original code: appendQueryParameter("scope", "activity:write,read_all")
New code: appendQueryParameter("scope", "activity:read_all,activity:write")

Thank you, thank you, thank you! Very much!


Dne úterý 21. září 2021 v 19:03:43 UTC+2 uživatel kingo...@gmail.com napsal:

Alex Algarate

unread,
Nov 1, 2022, 7:33:18 PM11/1/22
to Strava API
Hi Walker. 

I have problems with getting streams (I'm trying to get my watts info). 
What 8 headers do you have in your postman request? 

Captura de pantalla 2022-11-02 002705.png
I'm trying to do a GET request as you did but my response is: 
{
  "message": "Authorization Error",
  "errors": [
    {
      "resource": "Application",
      "field": "",
      "code": "invalid"
    }
  ]
}

I'm using my access token from the API. 

Also, I did a script in Python in which you can download all of your activities info but it's only global info such as average_speed, average_watts,  date, etc. 
Now I want streams (watts, distance, time) to make other analyses from my training activities. 

I hope you read this!

Thx

Reply all
Reply to author
Forward
0 new messages