SOLVED

Teams App Cannot Read File In OneDrive

%3CLINGO-SUB%20id%3D%22lingo-sub-1573732%22%20slang%3D%22en-US%22%3ETeams%20App%20Cannot%20Read%20File%20In%20OneDrive%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1573732%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20created%20a%20file%20in%20OneDrive%20using%3CBR%20%2F%3EPUT%20%2Fme%2Fdrive%2Froot%3A%7Bitem-path%7D%3A%2Fcontent%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20am%20using%20the%20following%20code%3A%3C%2FP%3E%3CP%20class%3D%22lia-indent-padding-left-30px%22%3Efetch(%60%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%3A%2FgcFile.txt%3A%2Fcontent%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%3A%2FgcFile.txt%3A%2Fcontent%3C%2FA%3E%60%2C%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20method%3A%20%22PUT%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20mode%3A%20%22cors%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20cache%3A%20%22no-cache%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20headers%3A%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%20%22Content-Type%22%3A%20%22text%2Fplain%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%20%22Authorization%22%3A%20%22Bearer%20%22%20%2B%20this.token%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20body%3A%20%22This%20is%20the%20contents%20of%20a%20new%20file.%22%2C%3CBR%20%2F%3E%7D)%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EThis%20works%20fine.%20I%20can%20view%20the%20file%20and%20its%20contents%20using%20a%20web%20browser.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20if%20I%20attempt%20to%20get%20the%20contents%20of%20the%20file%20using%3CBR%20%2F%3EGET%20%2Fme%2Fdrive%2Froot%3A%2F%7Bitem-path%7D%3A%2Fcontent%3CBR%20%2F%3Eit%20fails%20with%20the%20error%3CBR%20%2F%3E%3CFONT%20color%3D%22%23FF0000%22%3EGET%20%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%3A%2FgcFile.txt%3A%2Fcontent%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%3A%2FgcFile.txt%3A%2Fcontent%3C%2FA%3E%20401%20(Unauthorized)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20example%2C%20I%20am%20using%20the%20following%20code%3A%3C%2FP%3E%3CP%20class%3D%22lia-indent-padding-left-30px%22%3Efetch(%60%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%3A%2FgcFile.txt%3A%2Fcontent%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fv1.0%2Fme%2Fdrive%2Froot%3A%2FgcFile.txt%3A%2Fcontent%3C%2FA%3E%60%2C%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20method%3A%20%22GET%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20mode%3A%20%22no-cors%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20cache%3A%20%22no-cache%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20headers%3A%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Content-Type%22%3A%20%22text%2Fplain%22%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%22Authorization%22%3A%20%22Bearer%20%22%20%2B%20this.token%2C%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3CBR%20%2F%3E%7D)%3B%3C%2FP%3E%3CP%20class%3D%22lia-indent-padding-left-30px%22%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20know%20what%20I%20am%20doing%20wrong%3F%3C%2FP%3E%3CP%3EIs%20this%20the%20same%20problem%20as%20what%20is%20described%20in%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Ftroubleshoot%2Flists-and-libraries%2F401-error-when-using-graph-api-to-access-data%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Ftroubleshoot%2Flists-and-libraries%2F401-error-when-using-graph-api-to-access-data%3C%2FA%3E%3CBR%20%2F%3E%3F%3CBR%20%2F%3EIf%20so%2C%20is%20there%20any%20other%20workaround%20that%20does%20not%20involve%20changing%20the%20conditional%20access%20in%20the%20Azure%20Active%20Directory%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1573732%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1574998%22%20slang%3D%22en-US%22%3ERe%3A%20Teams%20App%20Cannot%20Read%20File%20In%20OneDrive%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1574998%22%20slang%3D%22en-US%22%3EDo%20you%20have%20a%20location%20based%20policy%20in%20effect%3F%20If%20so%2C%20I%20would%20say%20yes%20that%20is%20your%20issue%20and%20not%20aware%20of%20another%20way%20around%20it.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1576571%22%20slang%3D%22en-US%22%3ERe%3A%20Teams%20App%20Cannot%20Read%20File%20In%20OneDrive%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1576571%22%20slang%3D%22en-US%22%3EThanks%20for%20your%20help.%3C%2FLINGO-BODY%3E
Highlighted
Occasional 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
Highlighted
Best Response confirmed by George71 (Occasional 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.
Highlighted
Thanks for your help.