Roman Gelembjuk
Roman Gelembjuk

Reputation: 2005

OneDrive REST API and Sharepoint Online

I have the app that uses OneDrive API (MS graph) to access OneDrive free accounts and OneDrive for business.

The app works fine. In docs of the API i can see same API can be used also to access Sharepoint Online sites data.

How to do this? When i auth a user who has Sharepoint Online account with MS graph, there is only his drive (ondrive) but there is no his site listed.

How to get access to his sharepoint site too using same API?

Upvotes: 0

Views: 1530

Answers (3)

ngcbassman
ngcbassman

Reputation: 25

This endpoint to get the list of sites is not working, so the last answer is not valid anymore. https://graph.microsoft.com/v1.0/sites

I haven't found a way to do this, the discovery of sites, without admin consent. If the admin consent flow is not a problem you can try this workaround, use the endpoint of groups to ask for the groups that the user is member of, and you can use the groups to get the document libraries of the user.

To get the groups:

GET https://graph.microsoft.com/v1.0/me/memberOf

With the group id, you can use this endpoint:

GET https://graph.microsoft.com/v1.0/groups/{group-id}/drive

So if someone know how to do the discovery of sites for a user without admin consent, please share.

EDIT: I'm not sure why my answer was deleted, my answer basically has 2 things:

  • I gave notice that one answer here is not valid anymore.

  • I gave a possible other solution to the problem.

Upvotes: 0

Roman Gelembjuk
Roman Gelembjuk

Reputation: 2005

I have found how to work with sites using the Graph API.

To get list of sites there is the call

GET /v1.0/sites/

Then use the SITEID to get list of drives (in fact, top level folders)

GET /v1.0/sites/SITEID/drives

Then to get contents of a drive user

GET /v1.0/sites/SITEID/drives/DRIVEID/root/children

And all next calls are same as for onedrive drive

However, there is the problem i still can not solve. How to create new top level folder (new drive on a site). There is no API call for this

Upvotes: 1

Kashif Tahir
Kashif Tahir

Reputation: 311

I believe what you are looking for is the sites API. It lets you interact with a SharePoint site if you know the path or the id of the site. You can find the documentation for the api here:

https://dev.onedrive.com/resources/site.htm

There is no easy way to discover sites as of now. You can however search for a site. You can read more about it here:

https://dev.onedrive.com/sites/search.htm

Upvotes: 0

Related Questions