REST API Tutorial

Jira Api To Create Issue using PHP

Summary of learning

This rest api tutorial help to create issue into jira dashboard using Jira Rest api. I will take help of Jira rest api client php libs, You can use core jira rest api as well, but with help of this libs you can create clean code to use jira rest apis.

This rest api tutorial help to create issue into jira dashboard using Jira Rest api. I will take help of Jira rest api client php libs, You can use core jira rest api as well, but with help of this libs you can create clean code to use jira rest apis.

We need jira rest host url, username and password to configure jira client.I am assuming you have all these information, So lets start atlassian jira api example and uses.

Requirements for jira api

  • PHP >= 5.5.9
  • php JsonMapper
  • phpdotenv

We will install php-jira-rest-client using composer,

php composer.phar require lesstif/php-jira-rest-client "^1.7.0"

or add the following to your composer.json file.

{
    "require": {
        "lesstif/php-jira-rest-client": "^1.7.0"
    }
}

Then run composer install/update from command line.

Now include jira rest api client libs into top of the class where you want to access jira rest apis,
require 'vendor/autoload.php';

Create .env file and opened it, We are using dotenv modules so we are using .env file to load env variable into application.We will add below environments params into .env file.

JIRA_HOST="https://your-jira.host.com"
JIRA_USER="jira-username"
JIRA_PASS="jira-password"

The full code to create issue using jira pai and php is below,

setProjectKey("TEST")
                ->setSummary("records count not match")
                ->setAssigneeName("adam")
                ->setPriorityName("Critical")
                ->setIssueType("Bug")
                ->setDescription("User list count and all db records does not match")
                ->addVersion(["1.0.1", "1.0.3"])
                ->addComponents(['Component-1', 'Component-2']);
	
    $issueService = new IssueService();

    $ret = $issueService->create($issueField);
	
    //If success, Returns a link to the created issue.
    var_dump($ret);
} catch (JiraException $e) {
	print("Error Occured! " . $e->getMessage());
}

If you have requirements that needs our attentioN

Please feel free to contact us

We would love to hear from you

Share with your network

Facebook
Twitter
LinkedIn
WhatsApp
Email

This tutorial is intended to cover all the essentials steps and insights to understand Jira Api To Create Issue using PHP

Genislab Technologies

Learn further