When a new item is added to list, it has one column which I need to update using Rest API.
how can we do this at the time of adding new item?
You can just set the value of this field on the creation time as it shown here: Working with lists and list items with REST
url: http://site url/_api/web/lists/GetByTitle(‘Test')/items
method: POST
body: { '__metadata': { 'type': 'SP.Data.TestListItem' }, 'Title': 'Test'}
headers:
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value
accept: "application/json;odata=verbose"
content-type: "application/json;odata=verbose"
content-length:length of post body
Update 1. From you comment it seems that you need event receiver or custom form for that.
If you create an event receiver or workflow where you can hook the item added event and make call to the REST service and update the item.
If you have a custom form, you can make the REST call before creating item, and pass it result to that item on the creation time.
If I got your requirement correctly, you need two request to do this.
Adding Item
/_api/Web/Lists/GetByTitle('List Name')/Items
Add item using above end-point. In the response, you will get the ID of this item. Using this ID, make second request to update item.
Updating Item
/_api/Web/Lists/GetByTitle('SpTutorial')/getItemById('Id of old item')
Update #1
OP said that he is using newForm.aspx to add item. In that case, it is not possible to make second request to update this item.
So next workaround is Workflow
Create a Workflow which will update this item. Run this workflow on item created.
NewForm.aspx