LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-29-2017, 12:50 AM   #1
sathishncd
LQ Newbie
 
Registered: Dec 2017
Posts: 8

Rep: Reputation: Disabled
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($chCURLOPT_USERAGENT$agent);

//Set the URL
curl_setopt($chCURLOPT_URL$redmine_url );
if(
$request['type'] == 'post'){ 
//This is a POST query
curl_setopt($chCURLOPT_POST,1);
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
//Set the post data
curl_setopt($chCURLOPT_POSTFIELDS,$post_data);

curl_setopt($chCURLOPT_HTTPHEADER, array(                                                                          
'Content-Type: '.$request['content_type'],                                                                               
'Content-Length: ' strlen($post_data))                                                                       
);  
}
//We want the content after the query
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);                                  

curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);

//Follow Location redirects
curl_setopt($chCURLOPT_FOLLOWLOCATION1);

/*
Set the cookie storing files
Cookie files are necessary since we are logging and session data needs to be saved
*/

//curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
//curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

//Execute the action to login
$postResult curl_exec($ch);
//if($postResult == false){ return $info = curl_getinfo($ch);}
$response   =   json_decode($postResult);
//echo '<pre>'; print_r($response); echo '</pre>';
return $response;
}

}
//class_redmine

?>
here is my example.php:

PHP Code:
<?php
function get_redmine($methodName='',$data=''){
global 
$redmine_url $redmine_key;

$redmine_url 'http://192.168.12.231:80/';
$redmine_key 'API KEY';
include_once(
'curlcall.php');
$obj_redmine    =   new class_redmine();

#check Auth
$res $obj_redmine->get_projects();
if(!isset(
$res->projects) || (isset($res->total_count) && ($res->total_count)==0)){ return -1; }

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.
 
Old 12-29-2017, 07:04 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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)

Last edited by keefaz; 12-29-2017 at 07:05 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Application Issues with PHP & HTTPD Datsys Linux - Newbie 5 12-25-2017 09:15 AM
Crontab issue with the Redmine application visuharsha Linux - Server 3 11-22-2017 01:02 AM
[SOLVED] CentOS 6.2: Unable to fetch data from SSL sites (cURL, wget, etc) cheddarcheese Linux - General 18 10-02-2017 04:33 PM
Upgrade to Wheezy - Redmine / Ruby issues tomehb Debian 2 11-29-2012 04:20 AM
kmail pop fetch freezes the application dukeinlondon Linux - Desktop 2 08-29-2006 01:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration