5

I am always comfortable using JSOM, and I have used less of REST calls to access lists and its Items.

But now I have a requirement to use only REST to get item by its ID.

Is there any code snippet to get list item by its ID. I get ID in query string.

2 Answers 2

16

Try this (Excerpt from here):

function getListItem(url, listname, id, complete, failure) {
    // Getting our list items
    $.ajax({
        url: url + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            // Returning the results
            complete(data);
        },
        error: function (data) {
            failure(data);
        }
        });
    }
}
0
2

Official documentation from MS provides all possible examples.

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

This will return an individual item.

url: http://site url/_api/web/lists/GetByTitle('Test')/items(item id)
method: GET
headers:

Authorization: "Bearer " + accessToken
accept: "application/json;odata=verbose" or "application/atom+xml"

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.