In office scripts, I am trying to access csv files from a private Github repository. For this I use the following fetch call:
let token = "TOKEN"
const headers = {
"Authorization": `token ${token}`
}
let url = "https://raw.githubusercontent.com/ORGANISATION/REPO/main/data/example.csv
const res = await fetch(url, { headers });
When I inspect the browser dev tools I see the following error:
Access to fetch at "{github url}" from origin '{officescripts_url}.officescripts.microsoftusercontent.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
My office script console tells me this (I replaced some urls just to be sure):
{message: "Failed to fetch", name: "TypeError", stack: "TypeError: Failed to fetch at self.fetch ({url}) at importCSV ({url}) at async main (blob:{url}) at async _____wrapperMain (blob:{url})"}
When I put the same request in Insomnia, I can get my data without problems.
Is there a way to fix or work around this issue in Office scripts?
You can fetch text files from both private and public GitHub repositories.
Get the URL for the file
raw?token=...Example URLs
public
https://raw.githubusercontent.com/wandyezj/data/master/lists/shapes.list.txtprivate
https://raw.githubusercontent.com/wandyezj/simple-website/master/LICENSE?token=GHSAT0AAAAAACJUEK6DGRAUMSQW3WZA6YLMZKD2B3AExample Office Script