I'm on SharePoint Online and I need to use the Rest API to query the Pages library.
Normally, I'd use GET, but since I'm filtering on a Managed Metadata field, I have to use POST instead. For some reason reason, however, I'm not able to get some fields even though I have it on my ViewFields (I'm specifically interested in EncodedAbsUrl
or FileRef
).
Here's my query:
var query = '<Query><Where><Eq><FieldRef Name="RelatedTag"/><Value Type="TaxonomyFieldType">SomeValue</Value></Eq></Where></Query>';
var viewfields = '<ViewFields><FieldRef name="EncodedAbsUrl" /><FieldRef Name="Title" /></ViewFields>';
$.post({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Pages')/GetItems(query=@v1)?@v1={'ViewXml':'<View>"+query+viewfields+"</View>'}",
headers: {
"Accept": "application/json;odata=verbose",
"Content-Type" : "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
});
The response I get back is this:
As you can see, Title
is there, but EncodedAbsUrl
isn't. This also does not work if I put in FileRef
, FileLeafRef
, etc. RelatedTag
and all my other custom fields work though.