cancel
Showing results for 
Search instead for 
Did you mean: 

Can someone please help fix this javascript connection?

please-help-thx
Mt. Kenya

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
  ]);
}

 

 

1 ACCEPTED SOLUTION

igoramadas
Pico de Orizaba

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...

View solution in original post

2 REPLIES 2

igoramadas
Pico de Orizaba

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...

please-help-thx
Mt. Kenya