3

I am trying to run a rest query to return the top three items from within a folder in a pages library, I have the code working however when I try to add an 'orderby' or 'top' parameter to the query it then stops working.

Just wondering if anyone could please provide me with any help on this.

This is how the query currently looks:

_spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('Pages/HomepageNews')/Files?$select=Author/Title,Title,ArticleByLine,TimeCreated,ServerRelativeUrl&$orderby=ArticleStartDate desc&$expand=Author,ListItemAllFields&$top=3"

I have even tried this in postman which returns an "InvalidClientQueryException" I cant figure out why this is not working.

Any help would be appreciated.

  • Still no luck. I do actually need that though so well thought of. – Adam13Hylo Mar 16 '17 at 11:16
3

You also need to expand the property inside the ListItemAllFields as ListItemAllFields/ArticleStartDate.

The full url would be somewhat as below:

_spPageContextInfo.webAbsoluteUrl + "/_api/web/GetFolderByServerRelativeUrl('Pages/HomepageNews')/Files?$select=Author/Title,Title,ArticleByLine,TimeCreated,ServerRelativeUrl&$expand=Author,ListItemAllFields,ListItemAllFields/ArticleStartDate&$orderby=ListItemAllFields/ArticleStartDate desc&$top=3"

I have tested it on the modified field as below and its working:

/_api/web/GetFolderByServerRelativeUrl('/Pages/HomepageNews')/Files?$expand=Author,ListItemAllFields,ListItemAllFields/Modified&$orderby=ListItemAllFields/Modified desc&$top=3

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.