0

I've got a document library which has folders in it. I can get a given folder and iterate through the documents in the folder via REST just fine. What I need to do is get some of the list item properties (CreatedBy, ModifiedBy, Modified date) for each of those files.

I understand that what I need to do is to query the file as if it were a list item, using:

_api/web/lists/getbytitle('listName')/files(id)?

But I'm not seeing any way to get that list item ID for that file.

1

Try this:

"/_api/web/lists/getByTitle('listName')/items?$select=ID"

It should work.

Thanks,

Raj.

  • Doesn't that return all items? I need to get the ID of the specific item for the file in question I already have. – Scott Davis Feb 14 at 14:54
  • You can add filter attribute to filter the query, for example if you would like to filter by ID of 4 then you can use below REST query. "/_api/web/lists/getByTitle('Documents')/items?$select=ID&$filter=ID eq '4'" – Rajashekhar Sheelvant Feb 14 at 15:27
  • That's the problem- I've got the file, not the list item, so I need to get the ID of the list item the file is attached to. – Scott Davis Feb 14 at 19:42
  • In that case you can use any other associated field whose value you know. for example to filter based on title of the document you can use below REST query. "/_api/web/lists/getByTitle('Documents')/items?$select=ID&$filter=title eq 'documenttitle'" – Rajashekhar Sheelvant Feb 15 at 1:36
0

CreatedBy and ModifiedBy are SP.People fields. So you need to use expand in your query.

https://<siteURL>/_api/web/GetFolderByServerRelativeUrl('/FolderRelativePath')/Files('<File Name>')?$select=Author/Title,Editor/Title&$expand=Author,Editor

FolderRelativePath : '/sites/sitename/RootFolderName/SubfolderName'

Author: internal name of the 'Created By' column

Editor: internal name of the 'Modified By' column

Hope this helps

Thanks

0

Consider the file as an item then pass the file at the end of restApi endpoint:

_api/web/lists/getbytitle('listName')/items(id)/file?

Exanple

$.ajax({
url:"/_api/web/Lists/GetByTitle('Document_Test')/items(8)/file?$select=*,Author/Title&$expand=Author",
type: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data){
console.log(data.d)
},
error: function (err){
}
});

Good luck

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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