I am attempting to consume data from a SharePoint list in a non-SharePoint application using jQuery. I have enabled anonymous access on the SharePoint site and have added CORS headers to SharePoint via IIS to facilitate this. In my JavaScript code, I can do the following:
var siteUrl = 'http://mySharePointSite'; $.ajax({ url: siteUrl + '/_api/web/lists', method: 'GET', cache: false, headers: { 'Accept': 'application/json; odata=verbose' }, success: function (data) { console.log(data); }, error: function(data, errorCode, msg) { console.log('Error: ' + msg); } });
I can also get the properties of a list:
var siteUrl = 'http://mySharePointSite'; $.ajax({ url: siteUrl + "/_api/web/lists/getByTitle('Headlines')", method: 'GET', cache: false, headers: { 'Accept': 'application/json; odata=verbose' }, success: function (data) { console.log(data); }, error: function(data, errorCode, msg) { console.log('Error: ' + msg); } });
However, when I try to get items from the list, I always got 0 results even though there are items in the list:
var siteUrl = 'http://mySharePointSite'; $.ajax({ url: siteUrl + "/_api/web/lists/getByTitle('Headlines')/Items", method: 'GET', cache: false, headers: { 'Accept': 'application/json; odata=verbose' }, success: function (data) { console.log('Got ' + data.d.results.length + ' results.'); }, error: function(data, errorCode, msg) { console.log('Error: ' + msg); } });
The list inherits permissions from the parent web, so I don't believe I need to set additional permissions on the list. How can I query everything about the list except what is in it?
PS: I have also attempted to use the cross domain library with no luck. Every time I queried SharePoint with the following:
var siteUrl = 'http://mySharePointSite'; var request = new SP.RequestExecutor(siteUrl); request.executeAsync({ url: siteUrl + "/_api/web/lists", method: 'GET', headers: { 'Accept': 'application/json; odata=verbose' }, success: function(data) { console.log(data); }, error: function(data, errorCode, msg) { console.log('Error: ' + msg); } });
I always got the following result in the console:
Error: App Web is not deployed for this app's request url http://mySharePointSite.