7

I am trying to GET list items from SharePoint 2013 using REST API and ajax call.It is returning by default ATOM+XML. I want the response in JSON format. I tried the following however still same XML format response:

"/_api/lists/getbytitle(ListName)/Items/?$filter=lookupName/LookupNameInSourceListName eq 'col_Name'&                   $select=LinkTitle,Image,lookupName/LookupNameInSourceListName&$expand=lookupName/LookupNameInSourceListName&$orderby=TabOrder asc"

 $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });
1
  • The question is opened again. Thanks for your cooperation ;-)
    – Benny Skogberg
    Commented Jul 14, 2014 at 15:13

3 Answers 3

15

Thanks for the answer: i tried no luck.

This one worked for me:

$.ajax({
    url: Url,
    method: 'GET',
    beforeSend: function (XMLHttpRequest) {                     
        XMLHttpRequest.setRequestHeader("Accept", "application/json; odata=verbose");
    },              
    cache: true,
    error: function (data) {                    ////failure     },              
    success: function (data) {                  ////success     }
});
3
  • Mark this as answer, if it is the solution to your problem. Thank you!
    – Benny Skogberg
    Commented Jul 17, 2014 at 8:00
  • This worked for me also! I tried the other three options (odata missing, or nometadata, or minimalmetadata) but only verbose worked... any idea why the other options are broken? is my sharepoint an older version? see blogs.office.com/2014/08/13/… Commented Dec 29, 2014 at 19:55
  • Thank you! I'm on 2019 OnPrem and this worked for me. What's strange is that most of my api calls returned json by default, but new POSTS returned xml.
    – Ice Cube
    Commented Aug 17, 2020 at 23:17
1

Add to your header:

"Content-Type": "application/json;odata=verbose"
1

Although already answered, the below worked too :

request.Accept = "application/json;odata=verbose";
request.ContentType = "application/json;odata=verbose";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.