AnsweredAssumed Answered

I am trying add user by curl php, but don't add only sent me the admin info, here it's the code

Question asked by praveengollu on Mar 28, 2018

<?php
//login as admin by get method
//http://localhost:81/alfresco/s/api/login?u={username}&pw={password?}
$service_url = 'http://localhost:81/alfresco/s/api/login?u=admin&pw=*******';
$curl = curl_init($service_url);

header('Content-Type: application/json');
//echo "response-";
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);

if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}

$xml=simplexml_load_string($curl_response);
$alf_ticket = $xml[0];
echo $alf_ticket;
$uname = 'karthik';
//curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$service_url ='http://localhost:81/alfresco/s/api/people?alf_ticket='.$alf_ticket;// where you want to post data
echo $service_url;
header('Content-Type: application/json');
//echo "response-";
$curl = curl_init($service_url);
$curl_post_data = array(
'userName' => 'karthik',
'firstName' => 'karthik',
'lastName' => 'G',
'email' => 'karthik@example.com',
'password' => 'abc123'
);
$str_data = json_encode($curl_post_data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);// return the output in string format
curl_setopt($curl, 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($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$curl_response = curl_exec($curl);

if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response);
echo "13";
if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
die('error occured: ' . $decoded->response->errormessage);
}

echo 'response ok!';
//var_export($decoded->response);
//$alf_ticket=$decoded->response;

?>

 

 

 

if someone can help me please.

Outcomes