Create a person using restAPI

cancel
Showing results for 
Search instead for 
Did you mean: 
jackarnd
Established Member

Create a person using restAPI

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 !

4 Replies
douglascrp
Advanced II

Re: Create a person using restAPI

Hello.

 

Check the following blog post v1 REST API - Part 10 - People 

There you will find everything you need to know about it.

jackarnd
Established Member

Re: Create a person using restAPI

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 !

douglascrp
Advanced II

Re: Create a person using restAPI

Are you talking about the REST API again?

I think it would be better to start a new discussion on the topic.

jackarnd
Established Member

Re: Create a person using restAPI

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