Forum Discussion

George71's avatar
George71
Brass Contributor
Aug 07, 2020

Teams App Cannot Read File In OneDrive

 

I have created a file in OneDrive using
PUT /me/drive/root:{item-path}:/content

 

For example, I am using the following code:

fetch(`https://graph.microsoft.com/v1.0/me/drive/root:/gcFile.txt:/content`, {
    method: "PUT",
    mode: "cors",
    cache: "no-cache",
    headers: {
        "Content-Type": "text/plain",
        "Authorization": "Bearer " + this.token,
    },
    body: "This is the contents of a new file.",
});


This works fine. I can view the file and its contents using a web browser.

 

However, if I attempt to get the contents of the file using
GET /me/drive/root:/{item-path}:/content
it fails with the error
GET https://graph.microsoft.com/v1.0/me/drive/root:/gcFile.txt:/content 401 (Unauthorized)

 

For example, I am using the following code:

fetch(`https://graph.microsoft.com/v1.0/me/drive/root:/gcFile.txt:/content`, {
    method: "GET",
    mode: "no-cors",
    cache: "no-cache",
    headers: {
        "Content-Type": "text/plain",
        "Authorization": "Bearer " + this.token,
    },
});

 

Does anyone know what I am doing wrong?

Is this the same problem as what is described in
https://docs.microsoft.com/en-us/sharepoint/troubleshoot/lists-and-libraries/401-error-when-using-graph-api-to-access-data
?
If so, is there any other workaround that does not involve changing the conditional access in the Azure Active Directory?

  • Do you have a location based policy in effect? If so, I would say yes that is your issue and not aware of another way around it.
  • Do you have a location based policy in effect? If so, I would say yes that is your issue and not aware of another way around it.

Resources