SlideShare a Scribd company logo
1 of 10
Connect Jira Tempo Rest Api with PHP
Jira is well known team planning and management application. Thousands of companies using
Jira to assign work and tean activities. Jira provides facilities to add plugin as per your
requirement. Jira Tempo is one of famous Plugin to get the User, Task and Time-line Reports.
Tempo Restful Api build in Java. So we have build our Jira Class in PHP to use Tempo restful
apis..
Steps for connecting jira tempo rest api with php
1. Make sure CURL is enable in your server or php.ini file (php has phpinfo function to check
server setting). Check curl is working with below php code.
function isCurlInstalled() {
if (in_array ('curl', get_loaded_extensions())) {
return true;
}
else {
return false;
}
}
if (isCurlInstalled()) {
echo "installed";
} else {
echo "NOT installed";
}
2. Create Jira Class (You can create as per your convenient), 3 Private method and CURL
functions to connect Jira
class Jira {
private static $url = "http://192.168.0.59/"; // Tempo URL setup in API TOKEN
private static $credential = 'ezeelivetechnologies:test123'; // Jira Username and Password
private static $tempoApiToken = '15ezeelive-7f3f-40f2-a95f-4521918ba183';// Tempo Token Key
// Static function to Get Data
private static function getCURL($rest_url, $https = FALSE, $return_format = FALSE, $full_url = FALSE) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
if (empty($full_url))
curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url);
else
curl_setopt($ch, CURLOPT_URL, $rest_url);
curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential);
if (!empty($https)) {
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
if (!empty($return_format) && $return_format == 'json')
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
// Static function to POST Data
private static function postCURL($rest_url, $data = FALSE, $https = FALSE, $return_format = FALSE) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url);
curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential);
if (!empty($https)) {
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
if (!empty($return_format) && $return_format == 'json')
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
if (!empty($data))
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public static function getAllJiraProjectsKey() {
$return_data = array();
$rest_url = "rest/api/2/project";
$data = Jira::getCURL($rest_url, FALSE, $return_format = 'json');
if (!empty($data)) {
$data = json_decode($data, TRUE);
foreach ($data as $k => $dt) {
$return_data[] = $dt['key'];
}
}
return $return_data;
}
//......
//......
}
3. Now its time to get all the User list associated with Your Jira Project
public static function getJiraProjectUsers($proj_key) {
$return_data = array();
$rest_url = "rest/api/2/project/{$proj_key}/role";
$data = Jira::getCURL($rest_url, FALSE, $return_format = 'json');
if (!empty($data)) {
$data = json_decode($data, TRUE);
foreach ($data as $k => $dt) {
if (!is_array($dt)) {
$role_data = json_decode(Jira::getCURL($dt, FALSE, $return_format = 'json', TRUE), true);
if (!empty($role_data['actors'])) {
foreach ($role_data['actors'] as $v) {
if(!empty($v['displayName'])){
$return_data[] = array(
'disp_name' => $v['displayName'],
'uid' => !empty($v['id']) ?$v['id']:'',
'jira_auth' => $jauth,
'usr_name' => $v['name'],
'rates' => $rates,
'bill_ty' => $bill_type
);
}
}
}
}
}
}
return $return_data;
}
4. Once you get all the User Associated with Your Jira Project. You can get all the Worklog by
Jira User or Project Key
public static function getJiraUserWorklogs($jiraUserName,$fromDate,$toDate) { // By Jira UserName
$return_data = array();
$rest_url = "plugins/servlet/tempo-
getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal
se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&userName={$jiraUserName}";
$return_data = Jira::getCURL($rest_url);
return $return_data;
}
public static function getJiraProjectWorklogs($prjkey,$fromDate,$toDate) {
$return_data = array();
$rest_url = "plugins/servlet/tempo-
getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal
se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&projectKey={$prjkey}";
$return_data = Jira::getCURL($rest_url);
return $return_data;
}
5. Final the complete class is look like
class Jira {
private static $url = "http://192.168.0.59/"; // Tempo URL setup in API TOKEN
private static $credential = 'ezeelivetechnologies:test123'; // Jira Username and Password
private static $tempoApiToken = '15ezeelive-7f3f-40f2-a95f-4521918ba183';// Tempo Token Key
// Static function to Get Data
private static function getCURL($rest_url, $https = FALSE, $return_format = FALSE, $full_url = FALSE) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
if (empty($full_url))
curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url);
else
curl_setopt($ch, CURLOPT_URL, $rest_url);
curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential);
if (!empty($https)) {
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
if (!empty($return_format) && $return_format == 'json')
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
// Static function to POST Data
private static function postCURL($rest_url, $data = FALSE, $https = FALSE, $return_format = FALSE) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url);
curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential);
if (!empty($https)) {
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
if (!empty($return_format) && $return_format == 'json')
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
if (!empty($data))
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
public static function getAllJiraProjectsKey() {
$return_data = array();
$rest_url = "rest/api/2/project";
$data = Jira::getCURL($rest_url, FALSE, $return_format = 'json');
if (!empty($data)) {
$data = json_decode($data, TRUE);
foreach ($data as $k => $dt) {
$return_data[] = $dt['key'];
}
}
return $return_data;
}
public static function getJiraProjectUsers($proj_key) {
$return_data = array();
$rest_url = "rest/api/2/project/{$proj_key}/role";
$data = Jira::getCURL($rest_url, FALSE, $return_format = 'json');
if (!empty($data)) {
$data = json_decode($data, TRUE);
foreach ($data as $k => $dt) {
if (!is_array($dt)) {
$role_data = json_decode(Jira::getCURL($dt, FALSE, $return_format = 'json', TRUE), true);
if (!empty($role_data['actors'])) {
foreach ($role_data['actors'] as $v) {
if(!empty($v['displayName'])){
$return_data[] = array(
'disp_name' => $v['displayName'],
'uid' => !empty($v['id']) ?$v['id']:'',
'jira_auth' => $jauth,
'usr_name' => $v['name'],
'rates' => $rates,
'bill_ty' => $bill_type
);
}
}
}
}
}
}
return $return_data;
}
public static function getJiraUserWorklogs($jiraUserName,$fromDate,$toDate) { // By Jira UserName
$return_data = array();
$rest_url = "plugins/servlet/tempo-
getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal
se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&userName={$jiraUserName}";
$return_data = Jira::getCURL($rest_url);
return $return_data;
}
public static function getJiraProjectWorklogs($prjkey,$fromDate,$toDate) {
$return_data = array();
$rest_url = "plugins/servlet/tempo-
getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal
se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&projectKey={$prjkey}";
$return_data = Jira::getCURL($rest_url);
return $return_data;
}
}
If you have any query, suggestion or help on this jira tempo rest api, please visit
http://www.ezeelive.com/
Posted By : Ezeelive Technologies

More Related Content

Recently uploaded

audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
lolsDocherty
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
ChloeMeadows1
 

Recently uploaded (17)

Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdf
 
Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of apps
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdf
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirts
 
Free scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirtsFree scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirts
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
 
I’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 ShirtI’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 Shirt
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirts
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
GOOGLE Io 2024 At takes center stage.pdf
GOOGLE Io 2024 At takes center stage.pdfGOOGLE Io 2024 At takes center stage.pdf
GOOGLE Io 2024 At takes center stage.pdf
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Connect jira tempo rest api with PHP

  • 1. Connect Jira Tempo Rest Api with PHP Jira is well known team planning and management application. Thousands of companies using Jira to assign work and tean activities. Jira provides facilities to add plugin as per your requirement. Jira Tempo is one of famous Plugin to get the User, Task and Time-line Reports. Tempo Restful Api build in Java. So we have build our Jira Class in PHP to use Tempo restful apis.. Steps for connecting jira tempo rest api with php 1. Make sure CURL is enable in your server or php.ini file (php has phpinfo function to check server setting). Check curl is working with below php code. function isCurlInstalled() { if (in_array ('curl', get_loaded_extensions())) { return true; } else { return false; }
  • 2. } if (isCurlInstalled()) { echo "installed"; } else { echo "NOT installed"; } 2. Create Jira Class (You can create as per your convenient), 3 Private method and CURL functions to connect Jira class Jira { private static $url = "http://192.168.0.59/"; // Tempo URL setup in API TOKEN private static $credential = 'ezeelivetechnologies:test123'; // Jira Username and Password private static $tempoApiToken = '15ezeelive-7f3f-40f2-a95f-4521918ba183';// Tempo Token Key // Static function to Get Data private static function getCURL($rest_url, $https = FALSE, $return_format = FALSE, $full_url = FALSE) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); if (empty($full_url)) curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url); else curl_setopt($ch, CURLOPT_URL, $rest_url); curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential); if (!empty($https)) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } if (!empty($return_format) && $return_format == 'json') curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  • 3. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); return $data; } // Static function to POST Data private static function postCURL($rest_url, $data = FALSE, $https = FALSE, $return_format = FALSE) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url); curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential); if (!empty($https)) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } if (!empty($return_format) && $return_format == 'json') curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_POST, 1); if (!empty($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); return $data; }
  • 4. public static function getAllJiraProjectsKey() { $return_data = array(); $rest_url = "rest/api/2/project"; $data = Jira::getCURL($rest_url, FALSE, $return_format = 'json'); if (!empty($data)) { $data = json_decode($data, TRUE); foreach ($data as $k => $dt) { $return_data[] = $dt['key']; } } return $return_data; } //...... //...... } 3. Now its time to get all the User list associated with Your Jira Project public static function getJiraProjectUsers($proj_key) { $return_data = array(); $rest_url = "rest/api/2/project/{$proj_key}/role"; $data = Jira::getCURL($rest_url, FALSE, $return_format = 'json'); if (!empty($data)) { $data = json_decode($data, TRUE); foreach ($data as $k => $dt) { if (!is_array($dt)) { $role_data = json_decode(Jira::getCURL($dt, FALSE, $return_format = 'json', TRUE), true); if (!empty($role_data['actors'])) { foreach ($role_data['actors'] as $v) {
  • 5. if(!empty($v['displayName'])){ $return_data[] = array( 'disp_name' => $v['displayName'], 'uid' => !empty($v['id']) ?$v['id']:'', 'jira_auth' => $jauth, 'usr_name' => $v['name'], 'rates' => $rates, 'bill_ty' => $bill_type ); } } } } } } return $return_data; } 4. Once you get all the User Associated with Your Jira Project. You can get all the Worklog by Jira User or Project Key public static function getJiraUserWorklogs($jiraUserName,$fromDate,$toDate) { // By Jira UserName $return_data = array(); $rest_url = "plugins/servlet/tempo- getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&userName={$jiraUserName}"; $return_data = Jira::getCURL($rest_url); return $return_data; } public static function getJiraProjectWorklogs($prjkey,$fromDate,$toDate) { $return_data = array();
  • 6. $rest_url = "plugins/servlet/tempo- getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&projectKey={$prjkey}"; $return_data = Jira::getCURL($rest_url); return $return_data; } 5. Final the complete class is look like class Jira { private static $url = "http://192.168.0.59/"; // Tempo URL setup in API TOKEN private static $credential = 'ezeelivetechnologies:test123'; // Jira Username and Password private static $tempoApiToken = '15ezeelive-7f3f-40f2-a95f-4521918ba183';// Tempo Token Key // Static function to Get Data private static function getCURL($rest_url, $https = FALSE, $return_format = FALSE, $full_url = FALSE) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); if (empty($full_url)) curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url); else curl_setopt($ch, CURLOPT_URL, $rest_url); curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential); if (!empty($https)) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } if (!empty($return_format) && $return_format == 'json') curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  • 7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); return $data; } // Static function to POST Data private static function postCURL($rest_url, $data = FALSE, $https = FALSE, $return_format = FALSE) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_URL, Jira::$url . $rest_url); curl_setopt($ch, CURLOPT_USERPWD, Jira::$credential); if (!empty($https)) { curl_setopt($ch, CURLOPT_SSLVERSION, 3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } if (!empty($return_format) && $return_format == 'json') curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_POST, 1); if (!empty($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); return $data; }
  • 8. public static function getAllJiraProjectsKey() { $return_data = array(); $rest_url = "rest/api/2/project"; $data = Jira::getCURL($rest_url, FALSE, $return_format = 'json'); if (!empty($data)) { $data = json_decode($data, TRUE); foreach ($data as $k => $dt) { $return_data[] = $dt['key']; } } return $return_data; } public static function getJiraProjectUsers($proj_key) { $return_data = array(); $rest_url = "rest/api/2/project/{$proj_key}/role"; $data = Jira::getCURL($rest_url, FALSE, $return_format = 'json'); if (!empty($data)) { $data = json_decode($data, TRUE); foreach ($data as $k => $dt) { if (!is_array($dt)) { $role_data = json_decode(Jira::getCURL($dt, FALSE, $return_format = 'json', TRUE), true); if (!empty($role_data['actors'])) { foreach ($role_data['actors'] as $v) { if(!empty($v['displayName'])){ $return_data[] = array( 'disp_name' => $v['displayName'], 'uid' => !empty($v['id']) ?$v['id']:'', 'jira_auth' => $jauth, 'usr_name' => $v['name'],
  • 9. 'rates' => $rates, 'bill_ty' => $bill_type ); } } } } } } return $return_data; } public static function getJiraUserWorklogs($jiraUserName,$fromDate,$toDate) { // By Jira UserName $return_data = array(); $rest_url = "plugins/servlet/tempo- getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&userName={$jiraUserName}"; $return_data = Jira::getCURL($rest_url); return $return_data; } public static function getJiraProjectWorklogs($prjkey,$fromDate,$toDate) { $return_data = array(); $rest_url = "plugins/servlet/tempo- getWorklog/?addUserDetails=true&dateFrom={$data['sdate']}&dateTo={$data['edate']}&format=xml&diffOnly=fal se&tempoApiToken=" . Jira::$tempoApiToken . "&addIssueDetails=true&projectKey={$prjkey}"; $return_data = Jira::getCURL($rest_url); return $return_data; } }
  • 10. If you have any query, suggestion or help on this jira tempo rest api, please visit http://www.ezeelive.com/ Posted By : Ezeelive Technologies