SharePoint list item Rest API POST call
Sun Jan 02 2022 17:57:11 GMT+0000 (Coordinated Universal Time)
Saved by
@longshot
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
var listName="CL0206";
function AddListItem(){
var itemType = GetItemTypeForListName(listName);
var serverDetails='{"Server Name": "Production","Domain": "Gmail","Environment":"UAT"}';
var item = {
"__metadata": { "type": itemType },
"Title": "testing",
"ServerDetails":serverDetails
};
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
type: "POST",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
alert('Success');
},
error: function (data) {
alert(JSON.stringify(error));
}
});
}
// Get List Item Type metadata
function GetItemTypeForListName(name) {
return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
</script>
<input type="button" onclick="AddListItem()" value="AddListItem"/>
content_copyCOPY
https://sharepoint.stackexchange.com/questions/275754/how-to-apend-data-in-a-sharepoint-list-item-column-using-rest-api-post-call
Comments