I tried to run this function in excel online and seem to get an error on fetch. I've tried other variations and at times I get no errors but no response text. I'm new to typescript but I've successfully done the same/similar GET requests in Python with the requests library and also in VBA. Just would be nice to have this done in excel online. The headers for userid and pwd are because of anonymous authentication is required.
async function main(workbook: ExcelScript.Workbook) {
const myHeaders = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'userid': 'UserID',
'pwd': 'Password'
});
const myRequest = new Request('URL', {
method: 'GET',
headers: myHeaders
});
const response = await fetch(myRequest)
console.log(response.text)
}
I've also tried:
async function main(workbook: ExcelScript.Workbook) {
// Get the active worksheet.
let sheet = workbook.getActiveWorksheet();
// Display the current worksheet's name.
console.log(sheet.getName());
const myHeaders = new Headers({
'Content-Type': 'application/x-www-form-urlencoded',
'userid': 'UserID',
'pwd': 'Password'
});
const myRequest = new Request('URL', {
method: 'GET',
headers: myHeaders
});
fetch(myRequest)
.then(function(response) {
return response.text();
}).then(function(text) {
console.log(text);
});
}