Sharepoint - Make CAML query with in rest api call

There are a lot of things to cover in your question.

First, JSOM and REST are different things. JSOM is the JavaScript version of the Client Object Model. This is an API designed to be similar to the Server Object Model. The REST API is a data-centric web service designed to be used with modern web development.

Second, as the comments mention, you don't need to do a CAML query to do get list items with the REST API. This is something that is native to the API itself.

Here is a sample showing how to get list items using the REST API.

var call = jQuery.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('Products')/Items",
    type: "GET",
    dataType: "json",
    headers: {
        Accept: "application/json;odata=verbose"
    }
});
call.done(function (data, textStatus, jqXHR) {
    var message = jQuery("#message");
    message.text("Products");
    message.append("<br/>");
    jQuery.each(data.d.results, function (index, value) {
        message.append(value.Title);
        message.append("<br/>");
    });
});
call.fail(function (jqXHR, textStatus, errorThrown) {
    var response = "";
    try {
        var parsed = JSON.parse(jqXHR.responseText);
        response = parsed.error.message.value;
    } catch (e) {
        response = jqXHR.responseText;
    }
    alert("Call failed. Error: " + response);
});

If you do need to do a CAML query you can use this syntax:

var viewXml = {
    ViewXml: "<View>" +
        "<Query>" +
        "<Where><Eq>" +
        "<FieldRef Name='Category' LookupId='True' />" +
        "<Value Type='Lookup'>1</Value>" +
        "</Eq></Where>" +
        "</Query>" +
        "</View>"
}

var call = jQuery.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('Products')/GetItems(query=@v1)?" +
        "@v1=" + JSON.stringify(viewXml),
    type: "POST",
    dataType: "json",
    headers: {
        Accept: "application/json;odata=verbose",
        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
    }
});
call.done(function (data, textStatus, jqXHR) {
    var message = jQuery("#message");
    message.text("Beverages");
    message.append("<br/>");
    jQuery.each(data.d.results, function (index, value) {
        message.append(value.Title);
        message.append("<br/>");
    });
});
call.fail(function (jqXHR, textStatus, errorThrown) {
    var response = "";
    try {
        var parsed = JSON.parse(jqXHR.responseText);
        response = parsed.error.message.value;
    } catch (e) {
        response = jqXHR.responseText;
    }
    alert("Call failed. Error: " + response);
});

For more information you can check out the slides and demos from my Introduction to the Client Object Model and REST API conference talk.

I also have a course on Client Object Model and REST API development in the Pluralsight library that you may find valuable.

Tags:

List