1

In site collection features there is an option to enable Document ID Service. After doing this, whenever a document is uploaded to a document library, a unique document id that is a link to the doc is provided as a column. I would like to use the SharePoint API to retrieve this document only by this id.

Doing an API call like this works to some extent (using the internal name of the document ID column):

<url_SP_Site>/_api/web/lists/getbytitle('[Name_Document_Library]')/items?$select=Id&$filter=OData__dlc_DocId eq '[Id_you_search_for]'

In this type of format, the call only works if the document is in a document library with a specific name (if user has the file in a library name 'New Lib' it won't work).

Is there a way to get a document by its Id from ANY library in SharePoint?

In that way the document does not have to be uploaded into a library with a specific name. Additionally, the above API call does not return any of the column information from the document, it only returns the ID.

Can anyone modify the call so that the return includes ALL of the column information?

Any help would be greatly appreciated!

2 Answers 2

1

To get the document without providing document library name, use this:

<site-url>/_api/Web/GetFileById('<Document-ID>')

Source: Rest API to get a file using the GUID

1
  • I can see from that article that this is a problem others have had. Unfortunatly the solution did not work, the parem of that method requires a GUID, not sure why the author said could repro with Sarepoint's OData__dlc_DocId column value, the return throws an error saying that a 32 digit GUID is required as a parameter
    – Kyle Trent
    Feb 11, 2021 at 6:33
0

You could use SharePoint search rest api to achieve this. Use DocId=[Id_you_search_for] in the api:

https://yoursite/_api/search/query?querytext='DocId=a123'

Update:

If you want to get all the column information, you need to remove the select parameter in the endpoint:

<url_SP_Site>/_api/web/lists/getbytitle('[Name_Document_Library]')/items?$filter=OData__dlc_DocId eq '[Id_you_search_for]'
4
  • While this returns something, none of the information seems to be relevant, there is no column data nor any other information I could use to make api requests to get the column data (by columns I mean the fields in the document details pane where the file exists in the Sharepoint document lib)
    – Kyle Trent
    Feb 11, 2021 at 6:28
  • To get all the column information, check my update answer. In this way, we cannot get a document by its Id from ANY library in SharePoint. It's in specific list/library. Feb 12, 2021 at 7:38
  • That did the trick! Thanks :)
    – Kyle Trent
    Feb 25, 2021 at 18:43
  • You could accept my answer if it helps you. Mar 8, 2021 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.