Querying Sharepoint document in Graph API by web url

Viewed 46

I'm developping an application that aims to work with java and should allow crud operations on files. I do have an update functionnality that has to work with a library containing more than 5000 documents.

My goal is to retrieve a specific document based on its path. for this I use the property webUrl.

I do make an API call to the following URL

https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items?expand=fields,driveItem&$query=webUrl eq 'https://{sharepointUrl}/sites/{siteName} /{listName}/fileName.PDF'

Apparently, i do retrieve all the documents contained in the library. Previously, in a context where i had less than 5000 documents, I could use fields/fileLeafRef.

1 Answers

You can't filter item by webUrl.

Could you use shares endpoint in your case?

GET /shares/{shareIdOrEncodedSharingUrl}
GET /shares/{shareIdOrEncodedSharingUrl}/driveItem
GET /shares/{shareIdOrEncodedSharingUrl}/listItem

You need to transform the web URL into a sharing token.

Java code:

String webUrl = "https://{sharepointUrl}/sites/{siteName}/{listName}/fileName.PDF";
byte[] byteData = webUrl.getBytes();
String base64String = Base64.getEncoder().encodeToString(byteData);
String encodedUrl = "u!"+base64String.replace("=","").replace('/','_').replace('+','_');

Then call shares endpoint

GET /shares/{encodedUrl}
GET /shares/{encodedUrl}/driveItem
GET /shares/{encodedUrl}/listItem
Related