Hi,
I'm facing an issue with APi REST
I'm just trying to perform a simple search request :
this works perfectly though curl under bash
curl -s -u loginass "http://localhost:8080/alfresco/api/-default-/public/search/versions/1/search" --data '{"query":{"query":"ANCESTOR:\"workspace://SpacesStore/1928ee33-6f85-4543-bd67-3b8b29641946\""}}'
But there is no way to make it works under php
$url = "$SURLBASE/search";
$myquery = array("query" => 'ANCESTOR:"workspace://SpacesStore/'.$parentfolder.'"'); // AND irfm:status:Approved");
$processBody = array(
"query" => $myquery,
"paging" => array(
"maxItems" => "500000"
)
);
$processBody = array("query" => $myquery);
$processBodyjson=json_encode($processBody,JSON_UNESCAPED_SLASHES );
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
//to avoid curl_exec to perform as "echo"
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=UTF-8"));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_POSTFIELDS, $processBodyjson );
$json = curl_exec($ch);
$array = json_decode($json, 1);
curl_close($ch);
return($array);
The answer is :
Array
(
[error] => Array
(
[errorKey] => framework.exception.NotFound
[statusCode] => 404
[briefSummary] => 07238988 {0} introuvable
[stackTrace] => Pour des raisons de sécurité, le traçage de la pile n'est plus affiché, mais la propriété est conservée dans les versions précédente.
[descriptionURL] => https://api-explorer.alfresco.com
)
)
what am i doing wrong ?
thank you !
Solved! Go to Solution.
Actually, a mistake in the URL ...
I found out I used :
http://localhost:8080/alfresco/api/-default-/public/search/versions/1//search/
instead of :
Based on the error message, it suggests that the Alfresco server is not able to locate the resource you're requesting. This typically happens when the request URL or body is incorrect or not properly formatted. Verify that your php code is invoking to the same URL you're testing with curl.
Thanks for the answer
URL in PHP code is a copy/paste one from the bash command line ..
I guess this is a matter of syntax with the slashs .. but .. Is there a way to have a more detailed error (with the received data for example) ??
thanks again
Actually, a mistake in the URL ...
I found out I used :
http://localhost:8080/alfresco/api/-default-/public/search/versions/1//search/
instead of :
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.