I'm trying to get a sharing link from MS Graph API but it doesn't work. I'm connecting to company OneDrive.
internal async Task<string> GetDowloadLink(string fileName, string filePath)
{
var type = "view"; //read only link
var scope = "anonymous"; //anyone can access
Permission permission = await graphServiceClient.Users[oneDriveUserId].Drive.Root
.ItemWithPath(filePath + "\\" + fileName)
.CreateLink(type, scope, null, null, null)
.Request()
.PostAsync();
return permission.Link.WebUrl;
}
Request always returns:
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: invalidRequest
Message: Invalid request
I have similar method for deleting a file and it works OK.