08-23-2024 10:10 AM
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 !
09-02-2024 09:01 AM
Actually, a mistake in the URL ...
I found out I used :
http://localhost:8080/alfresco/api/-default-/public/search/versions/1//search/
instead of :
08-26-2024 02:15 AM
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.
08-26-2024 02:26 AM
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
09-02-2024 09:01 AM
Actually, a mistake in the URL ...
I found out I used :
http://localhost:8080/alfresco/api/-default-/public/search/versions/1//search/
instead of :
Explore our Alfresco products with the links below. Use labels to filter content by product module.