0

I am almost finished with my little app but need to be able to have a users click a button to download the route to file.

Looking into the Strava API Docs there is an endpoint which you can call:

https://www.strava.com/api/v3/routes/{id}/export_gpx

I have called this, but it seems to just return the response data for the gpx file which i understand. But how can i get that response downloaded as a file?

This is how i am calling the Strava API

    const init = async () => {
      try {
        const firstResponse = await axios({
          method: 'POST',
          url: 'https://www.strava.com/oauth/token',
          params: {
            client_id: process.env.GATSBY_STRAVA_CLIENT_ID,
            client_secret: process.env.GATSBY_STRAVA_CLIENT_SECRET,
            grant_type: 'refresh_token',
            refresh_token: process.env.GATSBY_STRAVA_REFRESH_TOKEN,
          },
        });
        const token = firstResponse.data.access_token;
        const secondResponse = await axios({
          method: 'GET',
          url: `https://www.strava.com/api/v3/routes/${props.data.contentfulRoutes.slug}`,
          headers: {
            Authorization: `Bearer ${token}`,
          },
        });

        setRoute(secondResponse.data);
        setAthlete(secondResponse.data.athlete);
      } catch (e) {
        console.log(e);
      }
    };

    init();
  }, []);

I was thinking of adding a third chain to call the /export_gpx endpoint. I would then want a button to fire that function or the call to the endpoint on click.

Ferran Buireu
  • 24,410
  • 6
  • 32
  • 55
mrpbennett
  • 926
  • 6
  • 23
  • This should help you: https://stackoverflow.com/questions/41938718/how-to-download-files-using-axios – Philipp Jun 13 '21 at 18:34

0 Answers0