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

PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
galaxypingy
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 

Recently uploaded (20)

PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 

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