Relate Document Library files with properties using REST API

%3CLINGO-SUB%20id%3D%22lingo-sub-89949%22%20slang%3D%22en-US%22%3ERelate%20Document%20Library%20files%20with%20properties%20using%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-89949%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20like%20to%20grab%20Document%20Library%20files%26nbsp%3Bthrough%20the%20API%2C%20this%20works%20with%20this%20URL%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%2F_api%2Fweb%2Ffolders('DocLib')%2FFiles%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWill%20result%20in%20something%20like%20this%3A%3C%2FP%3E%3CPRE%3ECheckInComment%3A%22%22%0ACheckOutType%3A2%0AContentTag%3A%22%7BB15D7491-63A1-446A-BACF-0082707CB916%7D%2C7%2C6%22%0ACustomizedPageStatus%3A0%0AETag%3A%22%22%7BB15D7491-63A1-446A-BACF-0082707CB916%7D%2C7%22%22%0AExists%3Atrue%0AIrmEnabled%3Afalse%0ALength%3A%2217008%22%0ALevel%3A1%0ALinkingUri%3A%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FProjects%2FTemplate%2FDocLib%2FSome_Document.docx%3Fd%3Dwb15d749163a1446abacf0082707cb916%22%0ALinkingUrl%3A%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FProjects%2FTemplate%2FDocLib%2FSome_Document.docx%3Fd%3Dwb15d749163a1446abacf0082707cb916%22%0AMajorVersion%3A3%0AMinorVersion%3A0%0AName%3A%22Some_Document.docx%22%0AServerRelativeUrl%3A%22%2Fsites%2FProjects%2FTemplate%2FDocLib%2FSome_Document.docx%22%0ATimeCreated%3A%222017-07-25T15%3A00%3A17Z%22%0ATimeLastModified%3A%222017-07-25T15%3A00%3A55Z%22%0ATitle%3A%22%22%0AUIVersion%3A1536%0AUIVersionLabel%3A%223.0%22%0AUniqueId%3A%22b15d7491-63a1-446a-bacf-0082707cb916%22%0Aodata.editLink%3A%22Web%2FGetFileByServerRelativePath(decodedurl%3D'%2Fsites%2FProjects%2FTemplate%2FDocLib%2FSome_Document.docx')%22%0Aodata.id%3A%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FProjects%2FTemplate%2F_api%2FWeb%2FGetFileByServerRelativePath(decodedurl%3D'%2Fsites%2FProjects%2FTemplate%2FDocLib%2FSome_Document.docx')%22%0Aodata.type%3A%22SP.File%22%3C%2FPRE%3E%3CP%3ETo%20get%20the%20extra%20properties%20for%20this%20document%20we%20could%20request%20this%20URL%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3E%2F_api%2Flists%2FgetByTitle('DocLib')%2Fitems%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20will%20result%20in%20something%20like%20this%3A%3C%2FP%3E%3CPRE%3EAuthorId%3A6%0ACheckoutUserId%3Anull%0AContentTypeId%3A%220x010100AA49F65C177A0C4AB6AF8289767F788D%22%0ACreated%3A%222017-07-25T15%3A00%3A17Z%22%0AEditorId%3A6%0AFileSystemObjectType%3A0%0AGUID%3A%2239ab1464-fd3b-483f-bb13-e3a5ba30413d%22%0AID%3A3%0AId%3A3%0AModified%3A%222017-07-25T15%3A00%3A55Z%22%0AOData__CopySource%3Anull%0AOData__UIVersionString%3A%223.0%22%0APublished%3Afalse%0AServerRedirectedEmbedUri%3A%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FProjects%2FTemplate%2F_layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7Bb15d7491-63a1-446a-bacf-0082707cb916%7D%26amp%3Baction%3Dinteractivepreview%22%0AServerRedirectedEmbedUrl%3A%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FProjects%2FTemplate%2F_layouts%2F15%2FWopiFrame.aspx%3Fsourcedoc%3D%7Bb15d7491-63a1-446a-bacf-0082707cb916%7D%26amp%3Baction%3Dinteractivepreview%22%0ATitle%3Anull%0Aodata.editLink%3A%22Web%2FLists(guid'df824189-a6c5-4d9f-8256-5b388fe977d2')%2FItems(3)%22%0Aodata.etag%3A%22%225%22%22%0Aodata.id%3A%229bf44adb-560f-4659-a39b-362c0f3288be%22%0Aodata.type%3A%22SP.Data.DocLibItem%22%3C%2FPRE%3E%3CP%3ENote%3A%20The%20%22Published%22%20property%20is%20a%20custom%20one.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20the%20question%20is%2C%20how%20are%20those%20records%20related%20or%20even%20beter%2C%20how%20could%20I%20fetch%20all%20this%20information%20at%20once%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20UniqueId%20from%20the%20'files'%20request%20matches%20the%20GUID%20in%20the%20property%20'%3CSPAN%3EServerRedirectedEmbedUrl'%20of%20the%20items%20request.%20So%20I%20could%20get%20the%20related%20file%20like%20this%26nbsp%3B%3CSTRONG%3E_api%2Fweb%2Ffolders('DocLib')%2FFiles%3F%24filter%3DUniqueId%20eq%20guid'b15d7491-63a1-446a-bacf-0082707cb916'%3C%2FSTRONG%3E%2C%20but%20I%20tought%20there%20should%20be%20a%20better%20way.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERegards%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ERoel%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-89949%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New Contributor

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

0 Replies