I'm developing a SharePoint-hosted app for SharePoint 2013 (in Office365), but I've a problem accessing lists within a SharePoint-hosted app.

My code is well printing the lists, but it only show me the 'Composed Looks' list and the 'Master Page Gallery' lists, I can't access the lists that I've created in my sharepoint site.

And when I try to access the 'Contacts' list (which exists in the sharepoint site where I deploy the app), it got this exception :

List 'Contacts' does not exist at site with URL 'https://mysharepointsite-03ea186502297f.sharepoint.com/SPHostedApp12

It thus seems that my app is running from another site than my main site, and that's why I can't access existing lists from my main website...

Does somebody know how to solve this and access existing lists in the main site?

Thanks a lot !

Here is my App.js code:

'use strict';

var gobbe = window.gobbe || {};

gobbe.ContactList = function () {
    // private members
    var createItem = function (lname, fname, bphone) {
        var ctx = new SP.ClientContext.get_current();
        var list = ctx.get_web().get_lists().getByTitle('Contacts');
        var listItemCreationInfo = new SP.ListItemCreationInformation();
        var newContact = list.addItem(listItemCreationInfo);
        newContact.set_item('Last Name', lname);
        newContact.set_item('First Name', fname);
        newContact.set_item('Business Phone', bphone);
        ctx.executeQueryAsync(success, error);
    readAll = function () {
        // Not implemented
    readAllSuccess = function () {
        // Not implemented
    updateItem = function () {
        // Not implemented
    updateItem = function (id, lname, fname, bphone) {
        // Not implemented
    removeItem = function (id) {
        // Not implemented
    success = function () {
    error = function (sender, args) {

    // public interface
    return {
        createContact: createItem,
        updateContact: updateItem,
        deleteContact: removeItem

gobbe.Collections = function () {
    // private members
    var site,

        getListCollection = function () {
            var ctx = new SP.ClientContext.get_current();
            site = ctx.get_web();
            listCollection = site.get_lists();
            ctx.load(listCollection,     'Include(Title,Id,Fields.Include(Title,Description))');
        ctx.executeQueryAsync(success, failure);

        success = function () {
            var html = [];

            // List Information
            var listEnumerator = listCollection.getEnumerator();
            while (listEnumerator.moveNext()) {
                // List Title

                // Fields Names
                var fieldEnumerator =     listEnumerator.get_current().get_fields().getEnumerator();
                while (fieldEnumerator.moveNext()) {


            // Show results

        failure = function (sender, args) {

    // public interface
    return {
        execute: getListCollection

$().ready(function () {
    // Show lists

    // Try to add a contact
    gobbe.ContactList.createContact('Cox', 'Brian', '555-555-5555');
    alert('Contact Created!');

    // Update it
    gobbe.ContactList.updateContact(1, 'Cox', 'Brian', '111-111-1111');
    alert('Contact Updated!');

    // Delete it
    alert('Contact Deleted!');
  • Please edit your post to remove confidential information if possible, rather than just delete it. Several people have spent their valuable time trying to help you and the content is now worthless otherwise. – SPDoctor Jun 19 '13 at 14:37
  • THe problem with just editing is that all previous versions is available if you have enough reps though. – Robert Lindgren Jun 20 '13 at 13:51
  • I've removed the private informations and rollbacked my post, sorry for the inconvenience. – ggobbe Jun 20 '13 at 19:27

Apps work in a different domain as compared to your host web. So, its a cross domain call when you try to access some list which resides in your host web from your app web. Normally browsers don't allow to make these cross domain calls for security reasons. However, in apps, to interact with host web, there is a library called SP.RequestExecutor.js, which is a cross domain libarary that you can use to make these calls. Please have a look at the following links that will help you in making these cross domain calls to access host web data inside an app web.




Hope that helps.

  • Thanks a lot, that's what I was looking for ! Your links were very useful ! – ggobbe Apr 9 '13 at 7:49

It sounds like that you forgot to give your app permissions: List 'Contacts' does not exist at site with URL.

When you install an app you will be asked for the rights to access a specific library or list for example.

You will have to add something like this... Example of what the markup looks like in an app manifest:

<AppPermissionRequests> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/></AppPermissionRequests>

  • Thanks a lot, my app do already have the required permissions, but as I said, it seems that it is running from some kind of sandboxed website in which I can't access lists from the top-level site. I think it is related to the context, in an autohosted app I get back the context of the main website, here the context is a subsite. But not sure :/ Anyway I can create/read/update/delete lists in my app but not lists from me top-level site (even with the permissions). – ggobbe Mar 26 '13 at 13:58

To access the list from Host web you would need to rely on the "standard tokens" and then use eithe JSOM or REST APi to access data.

 //Get the URI decoded URLs.
                hostweburl =
                appweburl =

Then you could use something like this:

 // Initialize the RequestExecutor with the app web URL.
                executor = new SP.RequestExecutor(appweburl);

                // Issue the call against the host web.
                // To get the title using REST we can hit the endpoint:
                //      app_web_url/_api/SP.AppContextSite(@target)/web/title?@target='siteUrl'
                // The response formats the data in the JSON format.
                // The functions successHandler and errorHandler attend the
                //      success and error events respectively.
                            appweburl +
                            "/_api/SP.AppContextSite(@target)/web/title?@target='" +
                            hostweburl + "'",
                        method: "GET",
                        headers: { "Accept": "application/json; odata=verbose" },
                        success: successHandler,
                        error: errorHandler

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.