Skip to main content

I have written a javascript command with the help of Chat GPT3 (I am not a developer) but would love some community assistance here! I'm looking to import activity data from Strava into an Equals spreadsheet. 


Can someone help me understand what I need to do to fix this? Any support is very appreciated!


Here's what I have:


 


const equals = require("equals");
const axios = require("axios");

const STRAVA_ACCESS_TOKEN = equals.getSecret("strava_api_key");
const STRAVA_ATHLETE_ID = equals.getSecret("strava_athlete_id");
const TABLE_NAME = "Activities";

const postData = async () => {
const resp = await axios({
method: "post",
url: `https://www.strava.com/api/v3/athletes/${STRAVA_ATHLETE_ID}/activities`,
headers: {
Authorization: `Bearer ${STRAVA_ACCESS_TOKEN}`
}
});
return resp.data;
};

const data = await postData();

equals.addHeaders(["Name", "Sport Type", "Elapsed Time", "Description", "Distance"]);

for(const record of data) {
equals.addRow([
record.name,
record.sport_type,
record.elapsed_time,
record.description,
record.distance
]);
}

 


 

Btw - I followed these steps to set up my API key: https://medium.com/@annthurium/getting-started-with-the-strava-api-a-tutorial-f3909496cd2d


The method should be "get" and not "post".

But more importantly, the access token is not the same as your API key. You actually should use the API key to fetch the access token. But explaining the whole OAuth2 flow here might be a bit of a stretch...


Reply