SOLVED

Teams App Cannot Read File In OneDrive

Brass Contributor

 

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-gr...
?
If so, is there any other workaround that does not involve changing the conditional access in the Azure Active Directory?

2 Replies
best response confirmed by George71 (Brass Contributor)
Solution
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.
Thanks for your help.
1 best response

Accepted Solutions
best response confirmed by George71 (Brass Contributor)
Solution
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.

View solution in original post