1

When I open browser with URL bellow, it throws error 404 (Not Found):

http://app-xxxxxxxxx.win-xxxxxxx:47699/_api/web/lists/getByTitle('RESTList2')/items
-1, System.ArgumentException List 'RESTList2' does not exist at site with URL 'http://app-08cf359d3cc937.win-85bfgfhvfnu:47699'.

I can view the list at this URL:

http://app-xxxxxxxxx.win-xxxxxxxx:47699/SharePointAddIn1/Lists/RESTList2/AllItems.aspx

Please help. I am stuck here for long time.

// Load the required SharePoint libraries.
$(document).ready(function () {

    // Get the URI decoded URLs.
    hostweburl =
        decodeURIComponent(
            getQueryStringParameter("SPHostUrl")
        );

    // The js files are in a URL in the form:
    // web_url/_layouts/15/resource_file
    var scriptbase = hostweburl + "/_layouts/15/";

    // Load the js files and continue to
    // the execOperation function.
    $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js", Jsom_AddItem);
        }
    );

    $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js", Jsom_LoadCamel);
        }
    );
});


function CreateListItemREST() {
    var listName = "RESTList2";
    var newItemTitle = "New Title Item";
    CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, newItemTitle, function () {
        alert("New Item has been created successfully.");
    }, function () {
        alert("Ooops, an error occured. Please try again.");
    });
}

// CREATE Operation
// listName: The name of the list you want to get items from
// weburl: The url of the web that the list is in. 
// newItemTitle: New Item title.
// success: The function to execute if the call is sucesfull
// failure: The function to execute if the call fails
function CreateListItemWithDetails(listName, webUrl, newItemTitle, success, failure) {

    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": newItemTitle
    };

    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "X-HTTP-Method": "MERGE",
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "IF-MATCH": "*"
        },
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });
}

// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
  • What is the display name of your list(Not the name in the url of list)?? in /_api/web/lists/getbytitle() endpoint, you need to provide the display name of list. – Ganesh Sanap Jan 9 at 7:07
  • Are you sure that list with title RESTList2 exists? You are using funtion getByTitle() so it looks for list by title, not url. Try to load all lists /_api/web/lists?$select=Title·and see if you can find RESTList2. – Lukas Nespor Jan 9 at 7:11
  • The display name of list "RESTList2" . And can be accessed from the url (can view) app-xxxxxxxxx.win-xxxxxxxx:47699/SharePointAddIn1/Lists/… – BISWANATH HALDER Jan 9 at 7:18
  • when I am trying to find the list using "_api/web/lists/?$select=Title" my list not showing their . But can be accessible from (Can add / edit /view item in list ) URL - app-xxxxxxxxxx.win-xxxxxxxx:47699/SharePointAddIn1/Lists/… – BISWANATH HALDER Jan 9 at 7:30
  • I just noticed that you are accessing wrong URL. It is missing the SharePointAddIn1 part. It should be http://app-xxxxxxxxx.win-xxxxxxx:47699/SharePointAddIn1/_api/web/lists/getByTitle('RESTList2')/items. _spPageContextInfo.siteAbsoluteUrl will give you only the root url without SharePointAddIn1 so you should use _spPageContextInfo.webAbsoluteUrl instead. – Lukas Nespor Jan 9 at 7:39
3

You are accessing wrong URL. It is missing the SharePointAddIn1 part. It should be:

http://app-xxxxxxxxx.win-xxxxxxx:47699/SharePointAddIn1/_api/web/lists/getByTitle('RESTList2')/items.

_spPageContextInfo.siteAbsoluteUrl will give you only the root url (site collection) without SharePointAddIn1 so you should use _spPageContextInfo.webAbsoluteUrl instead.

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.