06-07-2017 06:08 AM
Hello !
So I want to create a person using the RESTApi but I really don't know how to do it.
For the moment I did that (it's on a custom share page, hence I used the share proxy as you can see below) :
var boby = "{ \"id\": \"bob\",\"firstName\": \"Bob\", \"lastName\": \"LeBricoleur\", \"email\": \"bob@lebricoleur.com\", \"telephone\": \"6666666666\", \"enabled\": true,\"emailNotificationsEnabled\": true, \"password\": \"bob\" }";
console.log(boby);
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("creatingperson").innerHTML = this.responseText;
}
};
xhttp.open("POST", 'http://localhost:8081/share/proxy/alfresco-api/-default-/public/alfresco/versions/1/people', true);
xhttp.setRequestHeader("Content-Type", "application/json"); //--header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Authorization: Basic YWRtaW46YWRtaW4='
xhttp.send(boby);
}
But this doesn't do anything, it doesn't even give me response..
I also can't find a generic way to extract data from Alfresco so if anyone knows where is the doc about it..
Thanks in advance !
06-07-2017 01:54 PM
Hello.
Check the following blog post v1 REST API - Part 10 - People
There you will find everything you need to know about it.
06-08-2017 11:40 AM
Ok thank you ! It helped me to know what tu put ! But to resolve my problem I actually changed the way I coded my http request, I've put that instead and didn't use the share proxy :
var createperson = "{ \"id\": \"" + document.getElementById('login').value + "\",
\"firstName\": \"" + document.getElementById('firstName').value + "\",
\"lastName\": \"" + document.getElementById('lastName').value + "\",
\"email\": \"" + document.getElementById('mail').value + "\",
\"telephone\": \"" + document.getElementById('telephone').value + "\",
\"enabled\": true,
\"emailNotificationsEnabled\": true,
\"password\": \"" + document.getElementById('pwd2').value + "\"
}";
console.log(createperson);
var url = "http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people";
var method = "POST";
var async = true;
var request = new XMLHttpRequest();
request.onload = function () {
var status = request.status;
var data = request.responseText;
console.log("status :");
console.log(status);
console.log("data :");
console.log(data);
}
request.open(method, url, async);
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Authorization", "Basic YWRtaW46YWRtaW4=");
request.send(createperson);
And by the way do you know how I can create or extract a "workflow" ?
Thanks a lot for your help, again !
06-08-2017 11:50 AM
Are you talking about the REST API again?
I think it would be better to start a new discussion on the topic.
06-09-2017 04:20 AM
Well I don't know... Is it possible with the Rest Api to get the information you have in a workflow shown in the Share interface for example ?
Yes, you're right, I have created another question
Explore our Alfresco products with the links below. Use labels to filter content by product module.