1
votes

From Trying to search Sharepoint files using Microsoft Graph api i know that for accessing sharepoint i need to omit 'me' and use the endpoint.

https://graph.microsoft.com/v1.0/drive/root

But when i follow the documentation at https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_delete , I get error code 'unauthenticated' as response.

I am able to delete files from OneDrive using above method but not from sharepoint. What could be a possible solution?

2

2 Answers

1
votes

Here's how the Drives API works - every user has access to multiple drives. The OneDrive for Business is just one of the drives. Every SharePoint document library is also a drive.

In general, drives are accessed as /drives/<drive-id> as the second example on the reference page shows - https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/drive_get.

The OneDrive for Business can be accessed as /me/drive as a convenience shortcut.

Simply /drive points to the Shared Documents document library from the root site collection. Since the reference page doesn't say which drive should be returned, I'd stay away from this API until it gets documented. If the item you are trying to access is not there, it will be natural to get an error.

To unblock yourself:

  1. Make sure the file you are trying to delete is in the Shared Documents folder of the root SharePoint site collection.
  2. Make sure the user on whose behalf your app is acting has permissions to delete files in the desired folder.
  3. Make sure you are accessing the correct drive. When you get a drive item, there is a parentReference property that contains a driveId subproperty. Then, to access that item, you can do /drives/<drive-id>/items/<item-id>.
0
votes

Are you supplying the access token in your request header?

https://graph.microsoft.io/en-us/docs/authorization/app_authorization

You need to supply it for every request you want to perform:

The response body is a JSON-formatted string containing the access token (access_token). You need to supply this token to any ensuing HTTP requests to access Microsoft Graph API resources.