Introduction
In SharePoint online whenever a document is uploaded to SharePoint, a unique ID gets assigned to SharePoint online. This comes very useful when troubleshooting for issues such as search and policies getting applied to the documents. This is mainly useful in records management. Recently we have an issue with one of the document where the specific MCAS (Microsoft Cloud Access Security) is not getting enabled for SharePoint and for troubleshooting it is required to have document IDs. In this article, let's see some ways to get the document ID.
Using URL Decoder
When opening a word, PPT or excel document in browser you will have the ID embedded in the URL.
Here I have used Meyer’s web to decode the URL. In case you don’t know what meyer’s web docoder is it is an online encoder/decoder which can be used to decode/encode the URLs to get some required information. You can learn more by going to the link in the references section.
In this case the document ID is A3FE8BD4-C494-4280-A642-09A7DC50CB68
You can do the same process for Excel, PPT and you can get the document ID in the same manner. However, if you try the same process for PDF the document ID will not be embedded in URL.
Using REST API
You need to construct the REST API and get it from the request-response from the browser. You can use this REST API, for the word, Excel and PPT as well. I have used the following methods ‘GetFileByServerRelativeURL’. By hitting the below URL you can get the document ID.
https://cts229051.sharepoint.com/sites/o365poc/_api/web/GetFileByServerRelativeUrl('/sites/o365poc/Shared%20Documents/MerlinHubDoc4.pdf')/listItemAllFields
If you modify the above rest API URL with UniqueId at the end, you would directly get the Property in an XML output.
In my case the document ID for PDF document is 7c188559-43de-43f3-908f-cb36b2371872
Please make sure to update the above Rest API URL to your file uploaded in our org or personal dev tenant. You can look into the references section on how to work with files and folders in SharePoint using Rest API.
In the next article, we will take a look, how we can use Power Automate to get the document ID without having the above manual steps.
References