At some point in time, I want to update a specific Item in a list.

I Know that I have to use the REST call to update a specific item. Below is my URL.


"items(5)" I have hard coded the item ID.

My question is how do I get that ID "items(5)" of a specific Item from a list.

I have a Scenario where I will inserting an Item to a few fields and later I'll be updating that Item with additional data.

my code for inserting data to list.

 public void insertDataItems()

    try {
        CookieManager cookieManager = (CookieManager)CookieHandler.getDefault();
        cookies = cookieManager.getCookieStore().getCookies();
       // String body ="{ '__metadata': { 'type': 'SP.Data.ClockTrackListItem' },'UId' : '171028', 'CurrentDate' : '2016-08-05T04:00:00Z' ," +
       //         "'TimeIn' : '10:12:12' , 'TimeOut': '22:12:12' ,'TotalTime': '10:12:12' ,'Title': 'Dharma'}";
        String body ="{ '__metadata': { 'type': 'SP.Data.ClockTrackListItem' },'UId': '32156','TimeIn' : '06:00:00' , 'TimeOut': '08:00:00' ,'TotalTime': '02:00:00'}";

        Uri uri = Uri.parse("http://cloudapps.cctspl.com/sites/ClockInClockOut/_api/Web/lists/GetByTitle('ClockTrack')/items(5)");
        URL url = new URL(uri.toString());
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setDoInput (true);
        urlConnection.setRequestProperty("Accept", "application/json;odata=verbose");
        urlConnection.setRequestProperty("content-type", "application/json;odata=verbose");

        OutputStream os = urlConnection.getOutputStream();
        int resCode = urlConnection.getResponseCode();
        Log.d("Response Code :" ," "+resCode);
        InputStream inputStream = urlConnection.getInputStream();
        BufferedReader reader =new BufferedReader(new InputStreamReader((inputStream)));
        StringBuffer buffer = new StringBuffer();
        String line;
        while((line = reader.readLine()) != null)
            buffer.append(line + "\n");
        String restResult = buffer.toString();
        Log.d("----Buffer String-----:" , restResult);
        JSONObject jobj = new JSONObject(restResult).getJSONObject("d");
    catch (Exception e)
        Log.v("Retrieve List", e.toString());

  • 1
    Post code on how you are inserting the item Aug 14, 2016 at 11:43
  • Assuming that you know the filter criteria for the item, you can use caml to get the item reference and then get the item id from it.
    – nbi
    Aug 14, 2016 at 11:59
  • @nbi I don't know how to filter out a field with null value.Is there any way to capture the item Id while Inserting the data for the first time.
    – Dharma Raj
    Aug 14, 2016 at 12:03
  • @Amal Hashim I have update the code.
    – Dharma Raj
    Aug 14, 2016 at 12:03
  • 1
    @DharmaRaj that code only have update logic. How are you inserting the data. If I am not mistaken you want to insert and item and then later update the same item? Aug 14, 2016 at 12:15

2 Answers 2


Here is the example how to get the ID in the first call after you insert item in the list. Later you update the record with your above code.

You can use either REST call or JSOM. i have shown here JSOM.

var itemID  =""; function logTicket() {

    var clientContext = SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('List Name');

    var itemCreateInfo = new SP.ListItemCreationInformation();
    this.oListItem = oList.addItem(itemCreateInfo);
    oListItem.set_item('Title', '');    

        Function.createDelegate(this, this.onticketSucceeded),
        Function.createDelegate(this, this.onQueryFailed)

function onticketSucceeded() {

    itemID  = oListItem.get_id();
    //Here is the ID of newly inserted item in the list and assigned to global var itemID


function onQueryFailed(sender, args) {

 $(document).ready(function () {        

    }); });

Below mentioned example shows that the retrieval of list Items using SharePoint REST:

url: http://site url/_api/web/lists/GetByTitle('Test')/items
method: GET
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or "application/atom+xml"

If you want to retrieve the specific list item, then you can check the below code:

url: http://site url/_api/web/lists/GetByTitle('Test')/items(item id)
method: GET
    Authorization: "Bearer " + accessToken
    accept: "application/json;odata=verbose" or "application/atom+xml"

For more detailed information you can go through this :


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.