Hi Experts,
I am new in OPENFIRE and I need help in using REST API.
I manage to install OPENFIRE server successfully and create a new user from the admin console. However, when I try to create a new user by using the REST API, I failed. I have been trying to call the methods from REST API for few days using JQuery, Ajax, and Javascripts. But none of the codes manage to create a new user. I desperately need some helps from the experts. Thanks!!! These are some of my codes, I hope someone can point out my errors. Thanks again!!!
functionuserCreation() {
varxmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.open('POST', '[http://localhost:9090/plugins/restapi/v1/users](http://localhost:9090/plugins/restapi/v1/users)', true);
xmlhttp.setRequestHeader(‘Authorization’, ‘G4diPwo5’);
xmlhttp.setRequestHeader(“Content-Type”, “application/xml”);
var data =
“<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>” +
“” +
“test6” +
“p4ssword” +
“”;
xmlhttp.onreadystatechange = function() {
if (xmlhttp.status == 201) {
alert(“Update Successfully”);
}
}
xmlhttp.send(data);
}
function userCreation2() {
jQuery.ajax({
headers: {
“Authorization”: “G4diPwo5”,
},
type: ‘POST’,
contentType: “application/json; charset=utf-8”,
dataType: “json”,
url: '[http://localhost:9090/plugins/restapi/v1/users](http://localhost:9090/plugins/restapi/v1/users)',
data: {
“username”: “test6”,
“password”: “p4ssword”
},
success: function() {
alert(‘POST completed’);
},
error: function(xhr, status, error){
alert(xhr);
var err = eval("(" + xhr.responseText + “)”);
alert(err.Message);
}
})
}