Hi all, I am trying to run the following script for an external API call with a Bearer Token:
export interface DATOS {
count: number;
results: Result[];
skill_memberships: SkillMemberships;
meta: Meta;
}
export interface Meta {
count: number;
page_count: number;
page_number: number;
page_size: number;
}
export interface Result {
key: string;
id: string;
}
export interface SkillMemberships {
"87530265": The87530265;
}
export interface The87530265 {
level: number;
max_level: number;
created_at: string;
updated_at: string;
cached_skill_name: string;
skill_id: string;
creator_id: string;
user_id: string;
id: string;
}
export interface TESTBASIC {
userId: number;
id: number;
title: string;
body: string;
}
async function main(workbook: ExcelScript.Workbook): Promise<void>
{
var myHeaders = new Headers();
myHeaders.append("Authorization", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
console.log("Test2");
let url = encodeURI('https://api.xxxxxxxxxxxx.com/');
try
{
let fetchResult = await fetch(url, {
method: 'GET',
headers: {
"Access-Token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
"Accept": "application/json"
},
redirect: 'follow'
});
let json: DATOS = await fetchResult.json();
console.log(json);
} catch(e)
{
console.log(e);
}
}
But every time I try to run it to show me the result in the console, I always get the following error:
{message: "Failed to fetch", name: "TypeError", stack: "TypeError: Failed to fetch at
self.fetch (https://c0a4c0b1-8f01-4eaa-84f0-6434f1eb8473.officescripts.microsoftusercontent.com/eed0a086-3498-4f91-a377-1e0265ecc0cc/worker.js:99:13)
at main (blob:https://c0a4c0b1-8f01-4eaa-84f0-6434f1eb8473.officescripts.microsoftusercontent.com/5db7939c-4ae9-4802-8c9f-aed101943d56:183:45)
at async _____wrapperMain (blob:https://c0a4c0b1-8f01-4eaa-84f0-6434f1eb8473.officescripts.microsoftusercontent.com/5db7939c-4ae9-4802-8c9f-aed101943d56:209:20)"}
One of the doubts that I have regarding this script is if Excel Office Script is directly capable of working with this type of tokens, because perhaps if it cannot work with this type of tokens, this type of error will always appear, is this true? ? Or maybe this is due to an error in the text structure or interfaces? Is there a way to do this via Office Script, or would it only be possible to do it via VBA?
Regards