cancel
Showing results for 
Search instead for 
Did you mean: 

can't add person RESTful API

khanh
Champ in-the-making
Champ in-the-making
Hi,
i'm trying to create a new user using the REST javascript api.
but whenever I post to it, it always comes back with the logged in user info, and does not create the new user?

http://docs.alfresco.com/4.0/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Freferences%2FRESTful-P...

I've tried to append the alf_ticket to the url also and still doesn't create the user.
Can someone help?


ticket was generated from:

/alfresco/service/api/login?u=adminyser&pwd=adminpass


   function addperson(ticket){

      var url = "/alfresco/service/api/people?alf_ticket="+ticket;
      var userInfo = {userName : "testuser" , password: "testpassword" , firstName : "testfirst", lastName : "testlast", email : "testemail@test.com",  disableAccount: false, quote: -1, groups: []};
      $.ajax({
            type: 'POST',
            url: url,
            data: JSON.stringify(userInfo) ,
            dataType: 'json',
            success: function (response) {
   
            },
            error: function (response) {
            }
        });
   
   }

if seems like the post is not going in and it just returning the admin user.
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
Try changing your dataType from "json" to "application/json".

I notice that when I do:
curl -X POST -uadmin:admin http://localhost:8080/alfresco/service/api/people -H"content-type: json" -d@/Users/jpotts/Desktop/tmp.json

I get the same thing you get, but when I do:
curl -X POST -uadmin:admin http://localhost:8080/alfresco/service/api/people -H"content-type: application/json" -d@/Users/jpotts/Desktop/tmp.json

The user is created successfully.

(BTW, tmp.json includes your exact JSON).

Jeff

khanh
Champ in-the-making
Champ in-the-making
THANK YOU JEFF!
That did it!

In case anyone else runs into this isse,
there's a thing called a setting called contentType that needs to be set also,
form the jquery .ajax call.


not sure what you mean about the  tmp.json ?





$.ajax({
            type: 'POST',
            url: url,
            data: JSON.stringify(userInfo) ,
            dataType: 'json',
       contentType: 'application/json',
            success: function (response) {
   
            },
            error: function (response) {
            }
        });

jpotts
World-Class Innovator
World-Class Innovator
So glad that worked!

Regarding tmp.json I was just saying that the JSON I am posting (tmp.json) in my example is a copy-and-paste of the JSON you included in your example.

Jeff