-
Version :
Sonarqube 8.9.3LTS (build 48735) ; -
What I want :
I would like to get the total of my projects with the API : /api/components/search?qualifiers=TRK&ps=500 -
What I get :
I always get this response{"paging":{"pageIndex":1,"pageSize":500,"total":60}
I have 154 projects. -
What I did :
First, When i use a browser client, like RESTED Client, or with the browser directly, I get this json (>20ko) response :
`{
"paging": {
"pageIndex": 1,
"pageSize": 500,
"total": 154
},`
When I use php’s httpClient or CuRL commands from php I always get a total of 60 projects.
I use Symfony 5.4.3 and Php 8.1.0.
With native httpClient :
$url=$this->getParameter('sonar.url')."/api/components/search?qualifiers=TRK&ps=500";
$response = $this->client->request('GET', $url,
[ 'auth_basic' => [$this->getParameter('sonar.token'),''], 'max_duration' => 21.7 ,'timeout' => 2.5,
'headers' => [ 'Accept' => self::$strContentType, 'Content-Type' => self::$strContentType,] ]
);
With curl :
$ch = curl_init();
try {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Cache-Control: no-cache",
"content-type:application/json;charset=utf-8"
));
curl_setopt($ch, CURLOPT_USERPWD, $this->getParameter('sonar.token') . ":" .'');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data=curl_exec($ch);
if (curl_errno($ch)) { echo curl_error($ch); }
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($http_code == intval(200)){ echo "Ressource valide"; }
else{ echo "Ressource introuvable : " . $http_code; }
} catch (\Throwable $th) { throw $th;
} finally { curl_close($ch); }
So, I don’t know why I always 60 projects. I have no errors in debug mode.
- Debug mode
Hostname was NOT found in DNS cache
Added sonarqube2.franceagrimer.fr:0:192.168.100.246 to DNS cache
Trying 192.x.x.x...
GET /api/components/search?qualifiers=TRK&ps=500 HTTP/1.1
Accept: */*
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=
Accept-Encoding: gzip
User-Agent: Symfony HttpClient/Native
Host: sonarqube.xxx.fr
< HTTP/1.1 200
< Date: Sat, 29 Jan 2022 19:58:12 GMT
< Server: Apache/2.4.41 (Ubuntu)
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Cache-Control: no-cache, no-store, must-revalidate
< vary: accept-encoding
< Content-Encoding: gzip
< Content-Type: application/json
< Access-Control-Allow-Origin: http://xxx.xxx.fr
< Connection: close
< Transfer-Encoding: chunked
Please help me.