Forum Discussion

RoelVB's avatar
RoelVB
Copper Contributor
Jul 25, 2017

Relate Document Library files with properties using REST API

I would like to grab Document Library files through the API, this works with this URL:

/_api/web/folders('DocLib')/Files

 

Will result in something like this:

CheckInComment:""
CheckOutType:2
ContentTag:"{B15D7491-63A1-446A-BACF-0082707CB916},7,6"
CustomizedPageStatus:0
ETag:""{B15D7491-63A1-446A-BACF-0082707CB916},7""
Exists:true
IrmEnabled:false
Length:"17008"
Level:1
LinkingUri:"https://contoso.sharepoint.com/sites/Projects/Template/DocLib/Some_Document.docx?d=wb15d749163a1446abacf0082707cb916"
LinkingUrl:"https://contoso.sharepoint.com/sites/Projects/Template/DocLib/Some_Document.docx?d=wb15d749163a1446abacf0082707cb916"
MajorVersion:3
MinorVersion:0
Name:"Some_Document.docx"
ServerRelativeUrl:"/sites/Projects/Template/DocLib/Some_Document.docx"
TimeCreated:"2017-07-25T15:00:17Z"
TimeLastModified:"2017-07-25T15:00:55Z"
Title:""
UIVersion:1536
UIVersionLabel:"3.0"
UniqueId:"b15d7491-63a1-446a-bacf-0082707cb916"
odata.editLink:"Web/GetFileByServerRelativePath(decodedurl='/sites/Projects/Template/DocLib/Some_Document.docx')"
odata.id:"https://contoso.sharepoint.com/sites/Projects/Template/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/Projects/Template/DocLib/Some_Document.docx')"
odata.type:"SP.File"

To get the extra properties for this document we could request this URL:

/_api/lists/getByTitle('DocLib')/items

 

This will result in something like this:

AuthorId:6
CheckoutUserId:null
ContentTypeId:"0x010100AA49F65C177A0C4AB6AF8289767F788D"
Created:"2017-07-25T15:00:17Z"
EditorId:6
FileSystemObjectType:0
GUID:"39ab1464-fd3b-483f-bb13-e3a5ba30413d"
ID:3
Id:3
Modified:"2017-07-25T15:00:55Z"
OData__CopySource:null
OData__UIVersionString:"3.0"
Published:false
ServerRedirectedEmbedUri:"https://contoso.sharepoint.com/sites/Projects/Template/_layouts/15/WopiFrame.aspx?sourcedoc={b15d7491-63a1-446a-bacf-0082707cb916}&action=interactivepreview"
ServerRedirectedEmbedUrl:"https://contoso.sharepoint.com/sites/Projects/Template/_layouts/15/WopiFrame.aspx?sourcedoc={b15d7491-63a1-446a-bacf-0082707cb916}&action=interactivepreview"
Title:null
odata.editLink:"Web/Lists(guid'df824189-a6c5-4d9f-8256-5b388fe977d2')/Items(3)"
odata.etag:""5""
odata.id:"9bf44adb-560f-4659-a39b-362c0f3288be"
odata.type:"SP.Data.DocLibItem"

Note: The "Published" property is a custom one.

 

Now the question is, how are those records related or even beter, how could I fetch all this information at once?

 

The UniqueId from the 'files' request matches the GUID in the property 'ServerRedirectedEmbedUrl' of the items request. So I could get the related file like this _api/web/folders('DocLib')/Files?$filter=UniqueId eq guid'b15d7491-63a1-446a-bacf-0082707cb916', but I tought there should be a better way.

 

Regards,

Roel

No RepliesBe the first to reply

Resources