I have a document URL of a document saved in Office 365. I would like to retrieve the ItemID of the document using Graph API. How do I do that using Graph API?
This is the solution to the question https://learn.microsoft.com/en-us/graph/api/site-get?view=graph-rest-1.0
Related
We want read SharePoint Online document using DocId url (_layouts/15/DocIdRedir.aspx?ID=xxxx) instead of document library file path. Is there any way to achieve using graph API sdk ?
I'm using Microsoft graph API call to get details of organization .I need requirement to pass only tenant Id dynamically from front end in place of https://login.microsoftonline.com/tenantId/oauth2/v2.0/token for rest API in Microsoft graph .Can anyone help me out to solve this issue..
Thank you.
You can retrieve Tenant ID for user using Microsoft Graph like it is described in this answer on another question https://stackoverflow.com/a/63014761/481
then you can replace it in your URL for token request. I did something similar in this Arduino example https://github.com/panjkov/esp32-msgraph-presence/blob/main/src/MSGraphPresence/MSGraphPresence.ino
MS graph explorer offers many APIs with code snippet to search over ms office 365 but I can't find API to search files and documents in Teams or all the files and documents in SharePoint, OneDrive and Teams are saved in the same place? so we can use the same ms graph API to search files or documents over them all?!
You can use the Microsoft Search API provides one unified search endpoint that you can use to query data in the Microsoft cloud - messages and events in Outlook mailboxes, and files on OneDrive and SharePoint - that Microsoft Search already indexes. You can search messages, OneDrive/Sharepoint info etc.
One method by which you could use Ms Graph Api to search files is by wrapping a try and catch around the GET request. On the try section it will check if the file exists (basically retrieve the file), if it fails or the file is not present it will run the catch section.
try {
$drive = $graph->createRequest("GET",
"/sites/".$siteID."/drives/".$documentFolderID."/root:/$path/$target:/children")
->execute();
}catch(\Exception $e) {
"File not found"
}
Where $siteID can be retrieved from graph explorer using the following query
https://graph.microsoft.com/v1.0/sites?search={sitename}
Similarly $documentFolderID or the Document library of your site can be retrieved by the following query
https://graph.microsoft.com/v1.0/sites/{siteID}/drives
Note: This will retrieve all the documents from a Sharepoint site/Teams
To obtain all files/folders from OneDrive use the following query in MS Graph Explorer
https://graph.microsoft.com/v1.0/me/drive/root/children
Using MS Graph API, is there a way that we can find out the driveId of a certain folder with a given SharePoint URL?
The URL would look like this:
https://zpssgpatientsolutions.sharepoint.com/:f:/s/my_site/my_subsite/EllFGxYcxMNKt0kqOYH7OrIBo0AJu5NQ9-jc4rm2RTIKhA?e=IK11dT
There are not currently any APIs to convert from SharePoint URL to OneDrive driveId. On the other hand the OneDrive DriveItem APIs do return the webUrl of the SharePoint file in question.
I work with SharePoint Online drives(document libraries) with Microsoft Graph API (/drives call). With this API I can download/upload files but cannot work with permissions.
That's not a problem - I can do it with SharePoint Online REST API (with calls _api/web/GetListByTitle('Title')/hasuniqueroleassignments).
The main problem here is matching drive from MS Graph API and a corresponding list from SharePoint REST API. For now I match by title but I have several examples, when name field in MS Graph API is equal to "OneDrive", but title in List entity is Shared Pictures.
My question is: is there any way to match more precisely entities from Graph API and SharePoint REST API?
Thank you.
The Drive Item object has a SharePointIds property that will provide the information necessary to call the SharePoint REST API.
https://learn.microsoft.com/en-us/graph/api/resources/sharepointids?view=graph-rest-1.0
Use List resource, you could get list id.
Then use id to call rest api.
/_api/web/Lists(guid'54ca94c0-364e-4201-8fe7-a4c804769009')/hasuniqueroleassignments