Search code examples
node.jsapistrava

How to "turn" a page when asking for athlete activities in NodeJs?


In the Strava API, we can get the list Athlete Activities. However, we can only get 200 activities by page. I wonder how to get the other activities on the other pages?

I play with the parameters. When I put the per_page parameter to 1. I only get one activity even if the page parameter is to 60. As I am on NodeJs, I'm using fetch to call the API.

     api.getRefreshToken("REFRESH_TOKEN").then(strava => {

                    const headers = {
                        'Content-Type': 'application/json',
                        'Authorization': "Bearer " + strava.access_token
                    };
                    fetch("https://www.strava.com/api/v3/athlete/activities?per_page=1&page=60", {
                        method: 'GET',
                        headers: headers
                    }).then(responses => {
                        return responses.json();
                    }).then(
                        strava0 => {
                            console.log("Activities");
                            console.log(strava0);
                        });

                });

I would like to have the 60 activities I should normally have. However, I only get one.


Solution

  • In Strava API the maximum value of per_page (number of item per page) is 200 so you can set per_page=200 to limit the number of API call.

    If you have more than 200 activities, you have to send multiple requests using page parameter (i.e.: page=1 for activities 1-200; page=2 for activities 201-400).