I am updating a SharePoint list item in SharePoint framework web part, with the below code my item is getting updated, but it gives me the following error at the end :
Unexpected end of JSON input
private updateProperties(listname:string,requestdata:{})
{
let requestdatastr = JSON.stringify(requestdata);
requestdatastr = requestdatastr.substring(1, requestdatastr .length-1);
let requestlistItem: string = JSON.stringify({
'__metadata': {'type': this.getListItemType(listname)}
});
requestlistItem = requestlistItem.substring(1, requestlistItem .length-1);
requestlistItem = '{' + requestlistItem + ',' + requestdatastr + '}';
//Everthing is alright till here for sure.
this.context.spHttpClient.post(`${this.context.pageContext.web.absoluteUrl}/_api/web/lists/getbytitle('${listname}')/items`,
SPHttpClient.configurations.v1,
{
headers: {
"IF-MATCH": "*",
"X-HTTP-Method":"MERGE",
'Accept': 'application/json;odata=nometadata',
'Content-type': 'application/json;odata=verbose',
'odata-version': ''
},
body: requestlistItem
})
.then((response: SPHttpClientResponse): Promise<IListItem> => {
return response.json();
})
.then((item: IListItem): void => {
this.usermessage(`List Item created successfully... '(Item Id: ${item.Id})`);
this._renderListAsync();
}, (error: any): void => { //This message prints me the error
this.usermessage('List Item Updatation Error...');
console.log("Error in updation"+error.message);
});
}
MERGE
returns only Status Code like200
if it is success. May beresponse.json()
is causing the error. – Atish Dipongkor - MVP Jul 31 '17 at 7:34