1

I was shared access to a SharePoint folder on our Office 365 site.

The folder is deeply nested. Something like:

http://mycorp.sharepoint.com

Our Docs > Marketing > Company > Images

Inside the "Images" folder are a list of JPGs.

How can I use the Graph API to access this deeply nested folder?

I've tried something like:

https://graph.microsoft.com/v1.0/sites/mycorp.sharepoint.com:/Documents/Marketing/Company/Images:/Items

I feel I'm close but I'm just not sure how to access the nested folder structure.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
aherrick
  • 19,799
  • 33
  • 112
  • 188

1 Answers1

4

The format for referencing a path looks like this:

/v1.0/sites/root/drive/root:/{folder path}:/children

Using your example we have the following:

  1. https://graph.microsoft.com/v1.0/sites/root returns the root site of your SharePoint tenant.

  2. /drive/root returns default Drive for the Site. In this case, /Documents isn't actually a "folder", it's the default Drive for your root SharePoint

  3. :{folder path}: should be replaced by the path to the folder you're looking for. In this case /Marketing/Company/Images. The first : operator tells SharePoint to treat the following string as a file path. The second : tells SharePoint where the file path string ends.

  4. /children returns a list of DriveItem resources within the folder.

So you're complete URI should look something like this:

/v1.0/sites/root/drive/root:/Marketing/Company/Images:/children
Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
  • Thanks for the help! I'm able to see the data through the Graph Explorer. Can I not use "Application" authorization to view in my App with a Bearer Token? I've assigned the following App Level: Read managed metadata;Read and write items and lists in all site collections;Have full control of all site collections;Read items in all site collections;Read and write items in all site collections – aherrick Mar 28 '18 at 19:33
  • I'm referencing this article: https://stackoverflow.com/questions/35878044/ms-graph-api-onedrive-resource-not-found Just wasn't sure if that's still up to date – aherrick Mar 28 '18 at 19:34
  • 1
    That is no longer the case. You can see what scopes you need in the Graph Documentation: [`/children`](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_list_children) for example requires one of the following: `Files.Read.All`, `Files.ReadWrite.All`, `Sites.Read.All`, `Sites.ReadWrite.All`. – Marc LaFleur Mar 28 '18 at 19:46
  • Thanks! So inside the Azure Portal => Microsoft Graph API => Are these correct? 1) Read and write files in all site collections 2) Read files in all site collections 3) Create, edit, and delete items and lists in all site collections 4) Have full control of all site collections – aherrick Mar 28 '18 at 19:55
  • 1
    Nevermind! Appreciate your help. I found this which shows the conversions: https://developer.microsoft.com/en-us/graph/docs/concepts/permissions_reference – aherrick Mar 28 '18 at 20:15
  • Are there special permissions needed to actually read the JPG from HttpClient? I can get a JSON list of each file, but when I try to read the webUrl I'm geting unauthorized. – aherrick Mar 28 '18 at 21:33
  • I have the following enabled: `Read items in all site collections (preview)` `Read files in all site collections` – aherrick Mar 28 '18 at 23:23
  • Just a note, I was able to use the `@microsoft.graph.downloadUrl` property to grab the Image as a Byte Array and go from there. Still unsure on `webUrl` – aherrick Mar 29 '18 at 00:06
  • Ideally I would just be able to use my MVC site to slice and dice the graph endpoint, then just pipe the `webUrl` so I don't have to handle resizing or storing the image byte data. – aherrick Mar 29 '18 at 00:10
  • There are techniques for this but they really belong as a separate set of questions. – Marc LaFleur Mar 29 '18 at 15:18
  • Make sense. Thanks Marc. See here to sum up my above comments. https://stackoverflow.com/questions/49560362/microsoft-graph-api-read-office-365-sharepoint-list-and-pull-data-images – aherrick Mar 29 '18 at 15:55