PHP code example of pbrasseur / jira-client

1. Go to this page and download the library: Download pbrasseur/jira-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pbrasseur / jira-client example snippets


$api = new JiraClient\JiraClient('http://jira.hostname', 'login', 'password');

try {
    // Get an existing issue
    $issue = $api->issue()->get('JRA-123');

    // Print the issue id.
    echo $issue->getId();

    // Print the issue key.
    echo $issue->getKey();

    // Create new issue.
    $newIssue = $api->issue()
        ->create('JIRA', 'Suggestion')
        ->field(Field::SUMMARY, 'My Suggestion')
        ->field(Field::DESCRIPTION, 'Some description')
        ->execute();

    // Print the issue id.
    echo $newIssue->getId();

    $newIssue = $newIssue->update()
        ->field(Field::DESCRIPTION, 'Some new description')
        ->customField(10012, 'Value for custom field')
        ->fieldAdd(Field::LABELS, 'new-label')
        ->execute();

    // Print description of updated issue.
    echo $newIssue->getDescription();

    // Two ways for adding new comment.
    $newIssue->addComment("Some comment content");
    $api->issue()->addComment($newIssue->getKey(), "Another comment content");

    // Add new comment limited to the developer role.
    $newIssue->addComment("Only for developers", "role", "Developers");

    // Get reporter's name.
    $reporterName = $newIssue->getReporter()->getName();

    // Get an array of labels.
    $labels = $newIssue->getLabels();

    // Get an array of transitions for issue
    $transitions = $api->issue()->getTransitions($newIssue->getKey());

    // Executing transitions to change issue status
    $newIssue->transition()->execute(120);
    
    // Searches for issues using JQL
    $issues = new JiraClient\Request\SearchIterator($api, "project = Test");

    // or another way
    $issues = $api->issue()->search("project = Test");

    // Total count of found issues
    $total = $issues->getTotal();

    foreach ($issues as $issue) {
        $issue->update()
            ->fieldAdd(Field::LABELS, 'new-label')
            ->execute();
    }
} catch (\JiraClient\Exception\JiraException $e) {
    // exception processing
}