0

I need to get the no.of items in a SharePoint list which satisfying a condition.

https://<SITEURL>/_vti_bin/listdata.svc/LISTNAME/$count?&$filter=FIELDNAME eq 'abc'


using above url in browser gives me correct result.

So I Tried get it using below code,

    getItems("/_vti_bin/listdata.svc/LISTNAME/$count?&$filter=FIELDNAME eq 'abc'").done(function(data){
                console.log(data);
            });

getitems function,

function getItems(url){

    return $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        }
    });
}


But using this code gives an error "415 Unsupported Media Type".
please help.

2
/_vti_bin/listdata.svc/LISTNAME/$count?&$filter=FIELDNAME eq 'abc'

_vti_bin is the old (SP2007) SOAP WebServices endpoint (might still work),
But it is not the same as the Modern (SP2010) _api REST end point:

/_api/web/lists/getbytitle('LISTNAME')/items?$filter=FIELDNAME eq 'abc' 

You will get the resultst back in data.d.results, you can get the length of.

  • thanks, it worked. _vti_bin is working in web browser that confused me – Vishnu S May 18 '17 at 9:35
  • 1
    It is supposed to work but the syntax is different. See the jQuery / SPServices Library, that uses the SOAP endpoint and sometimes still has greater powers than REST – Danny '365CSI' Engelman May 18 '17 at 9:37
0

Instead of writing the result in done function you can use success and error methods. Your code look like

function getItems(url){

return $.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + url,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    }
 success: function (data) {
        console.log(data.d.results);
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
});
}
  • I tried that one, but getting error – Vishnu S May 18 '17 at 9:04
  • {"readyState":4,"responseText":"{\r\n\"error\": {\r\n\"code\": \"\", \"message\": {\r\n\"lang\": \"en-US\", \"value\": \"Unsupported media type requested.\"\r\n}\r\n}\r\n}","status":415,"statusText":"Unsupported Media Type"} – Vishnu S May 18 '17 at 9:08

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.