I am connecting to rest api which gives me json data with only 50 results at a time and i save the result in a variable ,but i want to retrieve 20000 records and i would like to know how i can build dynamic url to get all the data and save that in a variable.
Below is my current code
$url = "https://org.atlassian.net/rest/api/2/search?jql=project=PS+order+by+key&startAt=0";
$ch = curl_init();
$headers = array('Accept: application/json','Content-Type: application/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
$json = json_decode($result, true);}
In my url i have parameter to specify from which number i can return records like first request will be startAt=0 and second would be startAt=51 and thits would be startAt=101 or can i use a formula like x = total no of records/50 and then run curl x times and save all the result in variable or save all the json array and then merge it.Request you to help me on the same.
Thanks in Advance
There is a query parameter called maxResults
which defaults to 50. You can specify a higher number.
maxResults (int): the maximum number of issues to return (defaults to 50). The maximum allowable value is dictated by the JIRA property 'jira.search.views.default.max'. If you specify a value that is higher than this number, your search results will be truncated.
https://docs.atlassian.com/jira/REST/cloud/#api/2/search-search
I created a loop for this and resolved the problem.