How to fetch all issues from redmine application using curl PHP
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to fetch all issues from redmine application using curl PHP
here i am trying to fetch all issues from Redmine by using curl php below is the code which i used.But here i am able get 25 records only. my CURL.php:
PHP Code:
<?php # Redmine Api
class class_redmine{ function get_upload_token($filecontent){ global $redmine_url , $redmine_key; $upload_url = $redmine_url.'uploads.json?key='.$redmine_key; $request['type'] = 'post'; $request['content_type'] = 'application/octet-stream'; //$filecontent = file_get_contents('test.php'); return $token = $this->curl_redmine($upload_url,$request,$filecontent); //$token->upload->token; } #Issue function create_issue($post_data){ global $redmine_url , $redmine_key; $issue_url = $redmine_url.'issues.json?key='.$redmine_key; $request['type'] = 'post'; $request['content_type'] = 'application/json'; return $this->curl_redmine($issue_url,$request,$post_data); } function get_issue($issue_id='',$project_id=''){ global $redmine_url , $redmine_key; if($project_id!=''){ $issue_url = $redmine_url.'issues.json?key='.$redmine_key.'&project_id='.$project_id; }else{ $issue_url = ($issue_id=='')?$redmine_url.'issues.json?key='.$redmine_key : $redmine_url.'issues/'.$issue_id.'.json?key='.$redmine_key; } return $this->curl_redmine($issue_url,'',''); } #Projects function get_projects($project_id=''){ global $redmine_url , $redmine_key; $proj_url = ($project_id=='')?$redmine_url.'projects.json?key='.$redmine_key : $redmine_url.'projects/'.$project_id.'.json?key='.$redmine_key; return $this->curl_redmine($proj_url,'',''); } #Curl function curl_redmine($redmine_url,$request='',$post_data=''){ if(!isset($request['type'])){ $request['type']=null; } if(!isset($request['content_type'])){ $request['content_type']=null; } //Create a curl object $ch = curl_init(); //Set the useragent $agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//Set the URL curl_setopt($ch, CURLOPT_URL, $redmine_url ); if($request['type'] == 'post'){ //This is a POST query curl_setopt($ch, CURLOPT_POST,1); // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //Set the post data curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: '.$request['content_type'], 'Content-Length: ' . strlen($post_data)) ); } //We want the content after the query curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
switch($methodName){ case 'check_status' : return $login_integrate; ##check redmine integration in vision break;
##Project case 'projectAll' : return $obj_redmine->get_projects(); #used break; case 'projectById' : return $obj_redmine->get_projects($data['project_id']); break;
##Issues case 'issueAll' : return $obj_redmine->get_issue(); break; case 'issueByProjectId' : return $obj_redmine->get_issue('',$data['project_id']); break; case 'uploadFileToIssue' : return $obj_redmine->get_upload_token($data); break; default: return 0; } }
#get all issue $res = get_redmine('issueAll');
echo '<pre>';print_r($res); ?>
This code is giving only 25 records.at the end of my output it is saying like total:201 offset:0 limit:25 I can't understand how to get all issues please help anybody, i am new for php.
If API returns offset, I guess it includes paging. That means you have to fetch 25 records, then increment offset and use offset in post variable (what variable name? I don't know, maybe read API docs), and receive another set of 25 records
Or try to send a big limit value in post variable (again read API docs)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.