CAn someone show me an google apps script to get activity data into google drive?

I’ve found complicated answers with JSON thingies but I think it should be easier than that?

I have a bash script that says
curl -u API_KEY:XXXXXXAPIKEY https://intervals.icu/api/v1/athlete/XXXXXID/activities.csv > intervals.csv

which works fine but what is the APPS Script equivalent of that?

Chat GPT says its

function downloadAndSaveCSV() {
const apiKey = ‘XXXXXAPIKEY’; // Your API key
const apiUrl = ‘https://intervals.icu/api/v1/athlete/XXXXID/activities.csv’; // Your CSV URL
const folderId = ‘1PtBTg6ARpsDYNFVoh0yAkcz_jADCCwBR’; // Your Google Drive folder ID

// Encode API key for Basic Authentication
const encodedApiKey = Utilities.base64Encode(apiKey + ‘:’);

const urlOptions = {
‘method’: ‘get’,
‘headers’: {
‘Authorization’: 'Basic ’ + encodedApiKey
},
‘muteHttpExceptions’: true
};

try {
// Fetch the CSV file from the API
const response = UrlFetchApp.fetch(apiUrl, urlOptions);
const responseCode = response.getResponseCode();
const csvContent = response.getContentText();

// Log response code and content
Logger.log('Response Code: ' + responseCode);
Logger.log('Response Content: ' + csvContent);

if (responseCode === 200) {
  // Save the CSV content to Google Drive
  const fileName = 'intervals.csv';
  const folder = DriveApp.getFolderById(folderId);
  folder.createFile(fileName, csvContent, MimeType.CSV);
  Logger.log('CSV file saved successfully.');
} else {
  Logger.log('Failed to fetch CSV: ' + response.getContentText());
}

} catch (error) {
Logger.log('Error: ’ + error.message);
}
}

but it doesn’t work

Oh thanks to previous posters and a bit of sleep, I found the HRV Guided Training sheet and purloined some code from that! Yay!

This si what I was looking for

var resp = UrlFetchApp.fetch(apiUrl, {
headers: {
// use basic auth
‘Authorization’: 'Basic ’ + Utilities.base64Encode(
“API_KEY” + ‘:’ + apiKey, Utilities.Charset.UTF_8)
}
});

In case anyone cares, all this effort was to make a pretty publicly viewable workout summary using looker.

https://sites.google.com/view/chibi-exercise/home