I have a scenario where i would like to fetch all the files from multiple folders using REST API. I would like to filter the data in such a way so i can ignore the folders and fetch only the files inside all the files. I have the CAML query to do the recursive all activity but when i integrate with REST API its throwing a Bad request error. I checked the Network tab in IE it seems like the query in my code is not returning any data from REST API and it is failing when i use "GetItems". Could someone please let me know how to integrate CAML query in REST API.
var getContent = function (listTitle) {
var deferred = $q.defer();
if (listTitle == 'CandidateReports') {
var query = appweburl + "_api/SP.AppContextSite("+ hostweburl +")/web/lists/GetByTitle('" + listTitle + "')/GetItems";
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: query,
method: "POST",
headers: {
"Accept": "application/json; odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose"
},
data: JSON.stringify({
query: {
__metadata: {
type: "SP.CamlQuery"
},
ViewXml: "<ViewFields><FieldRef Name='FileLeafRef' /> <FieldRef Name='Title' /> </ViewFields> <QueryOptions> <ViewAttributes Scope='RecursiveAll' /> </QueryOptions> <Where> <Eq> <FieldRef Name='FSObjType' /> <Value Type='Integer'>0</Value> </Eq> </Where>"
}
}),
success: function (data, textStatus, xhr) {
console.log(data);
deferred.resolve(JSON.parse(data.body));
},
error: function (xhr, textStatus, errorThrown) {
deferred.reject(JSON.parse(xhr.body).error);
}
});
return deferred.promise;
};
return {
getContent: getContent
};