Here is the code I am using to add users to the SharePoint group from rest API
$.ajax({
url: siteUrl + "/_api/web/sitegroups(" + groupid + ")/users",
method: "POST",
body: JSON.stringify({
'__metadata': {
'type': 'SP.User'
},
'LoginName': uloginname
}),
headers: {
"accept": "application/json; odata=verbose",
"X-RequestDigest": $('#__REQUESTDIGEST').val(),
"content-type": "application/json; odata=verbose",
},
success: function(data) {
$("#result").append("New User:<b>" + email + "</b> added successfully to,\n SharePoint Group: " + groupname);
$("#cont").hide();
updateitem(id, email, "approve");
},
error: function(err) {
$("#result").append("error occured: " + JSON.stringify(err));
}
});
Here is the error I receive
error occured: {"readyState":4,"responseText":"{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected."}}}","responseJSON":{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"A node of type 'EndOfInput' was read from the JSON reader when trying to read the start of an entry. A 'StartObject' node was expected."}}},"status":400,"statusText":"Bad Request"}