I'm using graph API to iterate over a folder in OneDrive for Business. I'm attempting to generate "anonymous view" links for each item in the folder using the following call:
/v1.0/users('user-guid')/drive/items/item-id/microsoft.graph.createLink
with the body:
{
"type": "view",
"scope": "anonymous"
}
This works correctly for items that have already been given the "View link- no sign-in required" permission via the OneDrive UI. However, executing this call against an item that doesn't have this sharing option already set, results in the following return message:
{
"error": {
"code": "unauthenticated",
"message": "The caller is not authenticated.",
"innerError": {
"request-id": "1c3600ec-4861-4be4-9a7b-74264f488a80",
"date": "2016-03-13T02:30:10"
}
}
}
I know that this is not an authentication issue because my token works fine for all other calls (and calls against items that already have their file sharing set). I get the same behavior from the Microsoft Graph Explorer tool. If I manually set the "View link - no sign-in required" permission in OneDrive this call executes perfectly. My credentials for the API call are the same credentials I'm using to set the permissions in the OneDrive UI.
The documentation for microsoft.graph.createLink states
The createLink method will create a new sharing link if the specified link type doesn't already exist. If a sharing link of the specified type already exists for the app, the existing sharing link will be returned.
Any ideas what's going wrong here?