cancel
Showing results for 
Search instead for 
Did you mean: 

Add User by CURL PHP

lgonzalez
Champ in-the-making
Champ in-the-making
Hello Good Day,

I am trying add user by curl php, but don't add only sent me the admin info, here it's the code
      $data = array(
        "userName" => "ECASAS",
        "firstName" => "Eduardo",
        "lastName" => "Casas",
        "email" => "lgonzalez@emt.cl",
        "password"=>"asdasd"
      
      );


      $str_data = json_encode($data);

      $ch = curl_init();
      $username='admin';
      $password='*******';                    // initiate curl
      $url = "http://************/alfresco/service/api/people"; // where you want to post data
      curl_setopt($ch, CURLOPT_URL,$url);
      curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
      curl_setopt($ch, CURLOPT_POST, true);  // tell curl you want to post something
      curl_setopt($ch, CURLOPT_POSTFIELDS, $str_data); // define what you want to post
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
      $output = curl_exec ($ch); // execute
      
      curl_close ($ch); // close curl handle
      
      var_dump($output); // show output
      
if sameone can help me please.
2 REPLIES 2

romschn
Star Collaborator
Star Collaborator
Take a look at this forum post - https://forums.alfresco.com/comment/146735#comment-146735 where it is solved to invoke using the java code. You also need to ensure to pass the request data in valid json when you are invoking the webscript call.

Hope this helps.

lgonzalez
Champ in-the-making
Champ in-the-making
Hi,
I solved the problem, i added this code curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));.
Thank you.