2

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?

Community
  • 1
  • 1
Ajay Thomas
  • 173
  • 2
  • 12

2 Answers2

1

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>.
Tom Resing
  • 2,078
  • 1
  • 21
  • 28
  • Answers to points you suggested: 1) I added the desired user to the group: Team Site Owners of sharepoint 2) I am sure I am accessing the correct drive and item (file) as I am able to get the item properties and I am able to download the item also Inspite of above steps I am still getting error code 'unauthenticated' as response – Ajay Thomas Apr 28 '16 at 06:24
  • I have two asks: 1) Can you take a trace of the http request and response, e.g. with Fiddler. Wait for 1 hour (for the access token to expire) before you share it on a public cloud drive. 2) Add permission `Sites.ReadWrite.All` to your app and let me know whether anything changes. – Zlatko Michailov - MSFT Apr 28 '16 at 15:34
  • Related to your ask 2, I am not fully clear. When you say add permission does it mean configure permission to Microsoft Graph application in my app to enable Sites.ReadWrite.All (which is 'read and write items in all site collections')? Because there I only see option of 'read items in all site collections'. I have the feeling that I am missing something. – Ajay Thomas Apr 29 '16 at 09:42
  • I apologize for this - the permission is indeed missing from the list. It should be 'Edit or delete items in all site collections'. I'll bring it up with some people, and I'll get back to you. I'm sorry about that. – Zlatko Michailov - MSFT Apr 29 '16 at 15:43
  • Its alright. Please do get back to us when this is done. Thanks! – Ajay Thomas May 02 '16 at 05:29
  • The permission to modify drive items in SharePoint (outside of the user's OneDrive) should read `Have full access to all files you have access to`, but it doesn't look like it is available in Graph at the moment. I'll post another update once it has lilt up. – Zlatko Michailov - MSFT May 03 '16 at 18:59
0

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.

Jordi Ruiz
  • 487
  • 2
  • 11
  • Yes i am supplying the access token in my request header. Moreover I tried to do the same operation directly from the Graph Explorer provided at https://graph.microsoft.io/en-us/graph-explorer# . It doesnt work there also – Ajay Thomas Apr 27 '16 at 09:38
  • @AjayThomas, could you please show the request that you are performing? – Jordi Ruiz Apr 27 '16 at 10:42
  • THe request i am performing is this (from the graph explorer provided): DELETE https://graph.microsoft.com/v1.0/drive/items/01LKBWIO27DTDXSC24SFE2PGMUPMNRGXFE If i am doing the same thing with one drive (by adding the 'me' tag after v1.0 and using the item id accordingly, it works and the file gets deleted). I am suspecting it is something to do with permissions. I tried to change the permission of the file i was trying to delete but to no avail – Ajay Thomas Apr 27 '16 at 11:56