mgallagher
mgallagher

Reputation: 466

Accessing Files in a SharePoint Site via Graph: Bad Request

The documentation for using the MS Graph 1.0 API for accessing SharePoint files from libraries seems clear enough, if a bit indirect. My understanding is that I should be able to access the top level item of a library (and then its children via /children) by the following url scheme:

https://graph.microsoft.com/v1.0/sites/<my-tenant>.sharepoint.com:/sites/my-test-site:/drive/root

But I am only getting back an error telling me the Url is invalid:

{
  "error": {
    "code": "BadRequest",
    "message": "Url specified is invalid.",
    "innerError": {
      "request-id": "08bb72aa-f3be-4df0-b253-dacc4a8fe390",
      "date": "2019-07-08T16:38:07"
    }
  }
}

I've tried a few other url formats as well, such as specifying the drive specifically by Id /drives/<driveId>/root but had the same luck. I'm sure I am misunderstanding something. I'm using the "Path" format (:/sites/path-to-site:/ in the API because it is more natural than going and fetching an Id for everything I need to query.

Upvotes: 1

Views: 947

Answers (1)

LZ_MSFT
LZ_MSFT

Reputation: 4208

You need provide global Id of the site you want to access (global Id is <hostName>,<siteCollectionId>,<siteId>).To get the global id, in you test, we can use this.

https://graph.microsoft.com/v1.0/sites/<my-tenant>.sharepoint.com:/sites/my-test-site:/

And below API gives us a list of files on a specified site's default drive:

https://graph.microsoft.com/v1.0/sites/<hostName>,<siteCollectionId>,<siteId>/drive/root/children

If you want to access files on a specific list, all you need is the id of the list:

https://graph.microsoft.com/v1.0/sites/<hostName>,<siteCollectionId>,<siteId>/lists/<listId>/drive/root/children

Upvotes: 1

Related Questions