0

I have a list in SP 2013 with 4 Columns

Date Created -- Country -- Price in US Dollars -- Modified

After a bunch of help from the community I have created a Rest API for this list, but now i'm running into issues with the API pulling all of the data associated with the objects. I am trying to get the API to just pull the items in the columns above, which have 34 objects total in within each column.

This is the Select process that I have tried thus far, any help would be greatly appreciated. Still learning.

function retrieveListItems() {
  var siteUrl = _spPageContextInfo.webAbsoluteUrl;
   var fullUrl = siteUrl + "/_api/web/lists/GetByTitle('Demo List')/items?$select=Id,Title,Modified,Created"



//console.log(siteUrl);
console.log(fullUrl); 


$.ajax({
    url: fullUrl,
    type: "GET",
    //Tried with nometadata and verbose
    /*headers: {
        "accept": "application/json;odata=nometadata",
        "content-type": "application/json;odata=nometadata",
    },*/
    headers: {
        "accept": "application/json;odata=verbose",
        "content-type": "application/json;odata=verbose",
    },
    success: onQuerySucceeded,
    error: onQueryFailed
  });
 }

 function onQuerySucceeded(data) {
  var listItemInfo = '';

 $.each(data.d.results, function (key, value) {

    listItemInfo += '<strong>ID: </strong> ' + value.Id + ' ' +
        ' <strong>Title:</strong> ' + value.Title + ' ' +
        ' <strong>Date posted:</strong> ' + new Date(value.Created).toLocaleDateString() + ' ' +
        ' <strong>Date modified:</strong> ' + new Date(value.Modified).toLocaleDateString() + ' ' +
        '<br />';
});

$("#divGetListData").html(listItemInfo);
}


function onQueryFailed(sender, args) {
    alert('Error!');
}
0

If you are seeing all of the columns, the "select" is being ignored. Some versions require the odata keywords to be lowercase.

?$Select=

vs

?$select=

Also, if you are getting too much metadata back, you can try another option. Change this header to:

{"accept": "application/json; odata=verbose"}

one of these options:

data=verbose, odata=nometadata  or  odata=minimalmetadata
  • tried both options, you helped me last week with ingesting my api into power bi. Only way I could get it to ingest due to certain parameters is with get data --> web – hittle08 Apr 19 at 16:07
  • Now I can see the data in PowerBI query editor, but I see everything. Each individual object in the list is broken down into its own table, so i am trying to get it so I only see the objects in the list as stated in the first comment. I would like to only query each column. Please let me know if this makes sense. – hittle08 Apr 19 at 16:09
  • " get data --> web " What happens when you use the Power BI ODATA option? – Mike Smith - MCT - MVP Apr 19 at 16:32
  • Details: "OData: Request failed (404): The remote server returned an error: (404) Not Found. (Cannot find resource for the request $metadata.)" – hittle08 Apr 19 at 16:37
  • I posed my full set of code up top to see if you can notice anything wrong. – hittle08 Apr 19 at 17:37
0

In addition to what Mike Smith says in his answer, if you want to get the data from the Country and Price in US Dollars columns, you have to include them in the $select statement.

If you don't use any $select statement, you will get back all the columns from the list. Using $select is a way of telling SharePoint you only want the specified columns included.

So in your current $select, you are asking for only the ID, Title, Created and Modified columns. To get the four columns you mention at the start of your question, your $select should look something like:

$select=Created,Modified,Country,USPrice

although really it needs to include the internal names of the columns, and I don't have any way of knowing what the internal names of your Country and Price in US Dollars columns are.

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.