I am trying to integrate CAML query in rest API and trying to get data from a SharePoint List residing in host web. I am using method:

function getDataWithCaml(listName, caml) {
var executor = new SP.RequestExecutor(appWeb);
    var endpoint = appWeb + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('"
        + listName + "')/items?@target='" + siteUrl + "'";
    var requestData = {
                     { "type": "SP.CamlQuery" }
                  , "ViewXml": caml
    return executor.executeAsync({
        url: endpoint,
        method: "POST",
        data: requestData,
        headers: {
            "X-RequestDigest": $('#__REQUESTDIGEST').val(),
            "Accept": "application/json; odata=verbose",
            "Content-Type": "application/json; odata=verbose"

And the caml is simple as this:

var caml = "<View><Query><Where><Or><Eq><FieldRef Name='Title' /><Value Type='Text'>Test</Value></Eq><Eq><FieldRef Name='Title' /><Value Type='Text'>Test</Value></Eq></Or></Where></Query></View>";

I am getting error as:

Failed to load resource: the server responded with a status of 403 (FORBIDDEN)

I have given permission to the list as well as the web with full control.

Just want to know why is it coming up with this error.

I have tried changing the endpoint URL to siteUrl + "/_api//web/lists/getbytitle('" + listName + "')/items where siteUrl is host web URL.

Any help is appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.