PHP code example of lesstif / jira-cloud-restapi

1. Go to this page and download the library: Download lesstif/jira-cloud-restapi 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/ */

    

lesstif / jira-cloud-restapi example snippets


    

use JiraCloud\Configuration\ArrayConfiguration;
use JiraCloud\Issue\IssueService;

$iss = new IssueService(new ArrayConfiguration(
          [
               'jiraHost' => 'https://your-jira.atlassian.net',                                           
               'jiraUser' => 'jira-username',              
               'personalAccessToken' => 'your-token-here',
                
                // custom log config
               'jiraLogEnabled' => true,
               'jiraLogFile' => "my-jira-rest-client.log",
               'jiraLogLevel' => 'INFO',
        
               // to enable session cookie authorization (with basic authorization only)
               'cookieAuthEnabled' => true,
               'cookieFile' => storage_path('jira-cookie.txt'),
               // if you are behind a proxy, add proxy settings
               'proxyServer' => 'your-proxy-server',
               'proxyPort' => 'proxy-port',
               'proxyUser' => 'proxy-username',
               'proxyPassword' => 'proxy-password',
          ]
   ));


JiraCloud\Project\ProjectService;
use JiraCloud\Project\Project;
use JiraCloud\JiraException;

try {
    $p = new Project();

    $p->setKey('EX')
        ->setName('Example')
        ->setProjectTypeKey('business')
        ->setProjectTemplateKey('com.atlassian.jira-core-project-templates:jira-core-project-management')
        ->setDescription('Example Project description')
        ->setLeadName('lesstif')
        ->setUrl('http://example.com')
        ->setAssigneeType('PROJECT_LEAD')
        ->setAvatarId(10130)
        ->setIssueSecurityScheme(10000)
        ->setPermissionScheme(10100)
        ->setNotificationScheme(10100)
        ->setCategoryId(10100)
    ;

    $proj = new ProjectService();

    $pj = $proj->createProject($p);
   
    // 'http://example.com/rest/api/2/project/10042'
    var_dump($pj->self);
    // 10042 
    var_dump($pj->id);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Project\ProjectService;
use JiraCloud\Project\Project;
use JiraCloud\JiraException;

try {
    $p = new Project();

    $p->setName('Updated Example')
        ->setProjectTypeKey('software')
        ->setProjectTemplateKey('com.atlassian.jira-software-project-templates:jira-software-project-management')
        ->setDescription('Updated Example Project description')
        ->setLead('new-leader')
        ->setUrl('http://new.example.com')
        ->setAssigneeType('UNASSIGNED')
    ;

    $proj = new ProjectService();

    $pj = $proj->updateProject($p, 'EX');
   
    var_dump($pj);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $proj = new ProjectService();

    $pj = $proj->deleteProject('EX');
   
    var_dump($pj);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $proj = new ProjectService();

    $p = $proj->get('TEST');
	
    var_dump($p);			
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $proj = new ProjectService();

    $prjs = $proj->getAllProjects();

    foreach ($prjs as $p) {
        echo sprintf('Project Key:%s, Id:%s, Name:%s, projectCategory: %s\n',
            $p->key, $p->id, $p->name, $p->projectCategory['name']
        );			
    }			
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $proj = new ProjectService();

    $prjs = $proj->getAllProjects();

    // Extract and show Project Components for every Jira Project
    foreach ($prjs as $p) {
        var_export($proj->getProjectComponents($p->id));
    }
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $proj = new ProjectService();

    // get all project type
    $prjtyps = $proj->getProjectTypes();

    foreach ($prjtyps as $pt) {
        var_dump($pt);
    }

    // get specific project type.
    $pt = $proj->getProjectType('software');
    var_dump($pt);

} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $proj = new ProjectService();

    $vers = $proj->getVersions('TEST');

    foreach ($vers as $v) {
        // $v is  JiraCloud\Issue\Version
        var_dump($v);
    }
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $param = [
        'startAt' => 0,
        'maxResults' => 10,
        'orderBy' => 'name',
        //'expand' => null,
    ];

    $proj = new ProjectService();

    $vers = $proj->getVersionsPagenated('TEST', $param);

    foreach ($vers as $v) {
        // $v is  JiraCloud\Issue\Version
        var_dump($v);
    }
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Field\Field;
use JiraCloud\Field\FieldService;
use JiraCloud\JiraException;

try {
    $fieldService = new FieldService();

    // return custom field only. 
    $ret = $fieldService->getAllFields(Field::CUSTOM); 
    	
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}


JiraCloud\Field\Field;
use JiraCloud\Field\FieldService;
use JiraCloud\JiraException;

try {
    $field = new Field();
    
    $field->setName('New custom field')
            ->setDescription('Custom field for picking groups')
            ->setType('com.atlassian.jira.plugin.system.customfieldtypes:grouppicker')
            ->setSearcherKey('com.atlassian.jira.plugin.system.customfieldtypes:grouppickersearcher');

    $fieldService = new FieldService();

    $ret = $fieldService->create($field);
    
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Field Create Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

try {
    $issueService = new IssueService();
	
    $queryParam = [
        'fields' => [  // default: '*all'
            'summary',
            'comment',
        ],
        'expand' => [
            'renderedFields',
            'names',
            'schema',
            'transitions',
            'operations',
            'editmeta',
            'changelog',
        ]
    ];
            
    $issue = $issueService->get('TEST-867', $queryParam);
	
    var_dump($issue->fields);	
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueField;
use JiraCloud\JiraException;
use DH\Adf\Node\Block\Document;
use JiraCloud\ADF\AtlassianDocumentFormat;

try {
    $issueField = new IssueField();
    
    $code =<<<CODE

\$i = 123;
\$a = ['hello', 'world', ];
var_dump([\$i => \$a]);
CODE;

    $doc = (new Document())
        ->heading(1)            // header level 1, can have child blocks (needs to be closed with `->end()`)
          ->text('h1')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
        ->end()                 // closes `heading` node
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('we’re ')    // simple unstyled text
            ->strong('support') // text node embedding a `strong` mark
            ->text(' ')         // simple unstyled text
            ->em('markdown')    // text node embedding a `em` mark
            ->text('. ')        // simple unstyled text
            ->underline('like') // text node embedding a `underline` mark
            ->text(' this.')    // simple unstyled text
        ->end()                 // closes `paragraph` node
        ->heading(2)            // header level 2
            ->text('h2')        // simple unstyled text
        ->end()                 // closes `heading` node
        ->heading(3)
            ->text('heading 3')
        ->end()
        ->paragraph()           // paragraph
            ->text('also support heading.') // simple unstyled text
        ->end()                 // closes `paragraph` node
        ->codeblock('php')
           ->text($code)
        ->end()
    ;

    $descV3 = new AtlassianDocumentFormat($doc);         

    $issueField->setProjectKey('TEST')
                ->setSummary('something\'s wrong')
                ->setAssigneeNameAsString('lesstif')
                ->setPriorityNameAsString('Highest')
                ->setIssueTypeAsString('Story')
                ->setDescription($descV3)
                ->addVersionAsString('1.0.1')
                ->addVersionAsArray(['1.0.2', '1.0.3'])
                ->addComponentsAsArray(['Component-1', 'Component-2'])
                // set issue security if you need.
                ->setSecurityId(10001 /* security scheme id */)
                ->setDueDateAsString('2023-06-19')
                // or you can use DateTimeInterface
                //->setDueDateAsDateTime(
                //            (new DateTime('NOW'))->add(DateInterval::createFromDateString('1 month 5 day'))
                // )
            ;
	
    $issueService = new IssueService();

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

try {
    $issueField = new IssueField();

    $doc = (new Document())        
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('Full description for issue  ')    // simple unstyled text            
        ->end()                 // closes `paragraph` node
        
    $descV3 = new AtlassianDocumentFormat($doc);
    
    $issueField->setProjectKey('TEST')
                ->setSummary('something\'s wrong')
                ->setAssigneeNameAsString('lesstif')
                ->setPriorityNameAsString('Critical')
                ->setIssueTypeAsString('Bug')
                ->setDescription($descV3)
                ->addVersionAsString('1.0.1')
                ->addVersionAsString('1.0.3')
                ->addCustomField('customfield_10100', 'text area body text') // String type custom field
                ->addCustomField('customfield_10200', ['value' => 'Linux']) // Select List (single choice)
                ->addCustomField('customfield_10408', [
                    ['value' => 'opt2'], ['value' => 'opt4']
                ]) // Select List (multiple choice)
    ;
	
    $issueService = new IssueService();

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


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueField;
use JiraCloud\JiraException;
use JiraCloud\ADF\ADFMarkType;
use JiraCloud\ADF\AtlassianDocumentFormat;

try {
    $issueFieldOne = new IssueField();

    $doc = (new Document())        
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('Full description for issue  ')    // simple unstyled text            
        ->end()                 // closes `paragraph` node
    $descV3 = new AtlassianDocumentFormat($doc);
    
    $issueFieldOne->setProjectKey('TEST')
                ->setSummary('something\'s wrong')
                ->setPriorityNameAsString('Critical')
                ->setIssueTypeAsString('Bug')
                ->setDescription($descV3);

    $issueFieldTwo = new IssueField();

    $doc2 = (new Document())        
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('Full description for second issue  ')    // simple unstyled text            
        ->end()                 // closes `paragraph` node
	
    $desc2 = new AtlassianDocumentFormat(doc2);
    
    $issueFieldTwo->setProjectKey('TEST')
                ->setSummary('something else is wrong')
                ->setPriorityNameAsString('Critical')
                ->setIssueTypeAsString('Bug')
                ->setDescription($desc2);
    
    $issueService = new IssueService();

    $ret = $issueService->createMultiple([$issueFieldOne, $issueFieldTwo]);
    
    //If success, returns an array of the created issues
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}

->setIssueTypeAsString('Sub-task')
->setParentKeyOrId($issueKeyOrId)


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueField;
use JiraCloud\JiraException;
use JiraCloud\ADF\ADFMarkType;
use JiraCloud\ADF\AtlassianDocumentFormat;

try {
    $issueField = new IssueField();

    $doc = (new Document())        
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('Full description for sub-task issue  ')    // simple unstyled text            
        ->end()                 // closes `paragraph` node
    $descV3 = new AtlassianDocumentFormat(doc);
    
    $issueField->setProjectKey('TEST')
                ->setSummary('something\'s wrong')
                ->setAssigneeNameAsString('lesstif')
                ->setPriorityNameAsString('Critical')
                ->setDescription($descV3)
                ->addVersionAsString('1.0.1')
                ->addVersionAsString('1.0.3')
                ->setIssueTypeAsString('Sub-task')  //issue type must be Sub-task
                ->setParentKeyOrId('TEST-143')  //Issue Key
    ;

    $issueService = new IssueService();

    $ret = $issueService->create($issueField);

    //If success, Returns a link to the created sub task.
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueFieldV3;
use JiraCloud\Issue\DescriptionV3;
use JiraCloud\JiraException;

try {
    $issueField = new IssueFieldV3();

    $paraDesc =<<< DESC
Full description for issue
- order list 1
- order list 2
-- sub order list 1
-- sub order list 1
- order list 3 
DESC;
            $descV3 = new DescriptionV3();
            $descV3->addDescriptionContent('paragraph', $paraDesc);

            $issueField->setProjectKey('TEST')
                ->setSummary("something's wrong")
                ->setAssigneeAccountId('user-account-id-here')
                ->setPriorityNameAsString('Critical')
                ->setIssueTypeAsString('Bug')
                ->setDescriptionV3($descV3)
            ;
	
    $issueService = new IssueService();

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

try {
    $issueField = new IssueField();

    $issueField->setProjectKey('TEST')
                ->setSummary('something\'s wrong')
                ->setAssigneeNameAsString('lesstif')
                ->setPriorityNameAsString('Critical')
                ->setIssueTypeAsString('Bug')
                ->setDescription('Full description for issue')
                ->addVersionAsString('1.0.1')
                ->addVersionAsString('1.0.3')
                ->addCustomField('customfield_10100', 'text area body text') // String type custom field
                ->addCustomField('customfield_10200', ['value' => 'Linux']) // Select List (single choice)
                ->addCustomField('customfield_10408', [
                    ['value' => 'opt2'], ['value' => 'opt4']
                ]) // Select List (multiple choice)
    ;
	
    $issueService = new IssueService();

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


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
    $issueService = new IssueService();

    // multiple file upload support.
    $ret = $issueService->addAttachments($issueKey, 
        ['screen_capture.png', 'bug-description.pdf', 'README.md']
    );

    print_r($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'Attach Failed : ' . $e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\Issue\IssueField;
use JiraCloud\JiraException;
use JiraCloud\ADF\ADFMarkType;
use JiraCloud\ADF\AtlassianDocumentFormat;

$issueKey = 'TEST-879';

try {			
    $issueField = new IssueField(true);

    $doc = (new Document())        
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('This is a shorthand for a set operation on the summary field ')    // simple unstyled text            
        ->end()                 // closes `paragraph` node
     ;
    
    $descV3 = new AtlassianDocumentFormat(doc);
            
    $issueField->setAssigneeNameAsString('admin')
                ->setPriorityNameAsString('Blocker')
                ->setIssueTypeAsString('Task')
                ->addLabel('test-label-first')
                ->addLabel('test-label-second')
                ->addVersionAsString('1.0.1')
                ->addVersionAsString('1.0.2')
                ->setDescription($descV3)
    ;

    // optionally set some query params
    $editParams = [
        'notifyUsers' => false,
    ];

    $issueService = new IssueService();

    // You can set the $paramArray param to disable notifications in example
    $ret = $issueService->update($issueKey, $issueField, $editParams);

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'update Failed : ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

try {
    $issueKey = 'TEST-123';

    $issueService = new IssueService();

    $addLabels = [
        'triaged', 'customer-request', 'sales-request'
    ];

    $removeLabel = [
        'will-be-remove', 'this-label-is-typo'
    ];

    $ret = $issueService->updateLabels($issueKey,
            $addLabels,
            $removeLabel,
            $notifyUsers = false
        );

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'updateLabels Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

try {
    $issueKey = 'TEST-123';

    $issueService = new IssueService();

    $addVersions = [
        '1.1.1', 'named-version'
    ];

    $removeVersions = [
        '1.1.0', 'old-version'
    ];

    $ret = $issueService->updateFixVersions($issueKey,
            $addVersions,
            $removeVersions,
            $notifyUsers = false
        );

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'updateFixVersions Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
	$issueService = new IssueService();

    // if assignee is -1, automatic assignee used.
    // A null assignee will remove the assignee.
    $accountId = 'replace-to-user-account-id';

    $ret = $issueService->changeAssigneeByAccountId($issueKey, $accountId);

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'Change Assignee Failed : ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
	$issueService = new IssueService();

    $accountId = 'usre-account-id';

    $ret = $issueService->changeAssigneeByAccountId($issueKey, $accountId);

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'Change Assignee Failed : ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
    $issueService = new IssueService();

    $ret = $issueService->deleteIssue($issueKey);
    // if you want to delete issues with sub-tasks
    //$ret = $issueService->deleteIssue($issueKey, array('deleteSubtasks' => 'true'));

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'Remove Issue Failed : ' . $e->getMessage());
}


DH\Adf\Node\Block\Document;
use JiraCloud\ADF\AtlassianDocumentFormat;
use JiraCloud\Issue\Comment;
use JiraCloud\Issue\IssueService;

$issueKey = 'TEST-879';

try {			
    $comment = new Comment();

    $code =<<<CODE

\$i = 123;
\$a = ['hello', 'world', ];
var_dump([\$i => \$a]);
CODE;

    $doc = (new Document())
        ->heading(1)            // header level 1, can have child blocks (needs to be closed with `->end()`)
            ->text('h1')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
        ->end()                 // closes `heading` node
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('we’re ')    // simple unstyled text
            ->strong('support') // text node embedding a `strong` mark
            ->text(' ')         // simple unstyled text
            ->em('markdown')    // text node embedding a `em` mark
            ->text('. ')        // simple unstyled text
            ->underline('like') // text node embedding a `underline` mark
            ->text(' this.')    // simple unstyled text
            ->text(' date=' . date("Y-m-d H:i:s"))
        ->end()                 // closes `paragraph` node
        ->heading(2)            // header level 2
          ->text('h2')        // simple unstyled text
        ->end()                 // closes `heading` node
        ->heading(3)
            ->text('heading 3')
        ->end()
        ->paragraph()           // paragraph
          ->text('also support heading.') // simple unstyled text
        ->end()                 // closes `paragraph` node
        ->codeblock('php')
         ->text($code)
        ->end()
    ;

    $comment->setBodyByAtlassianDocumentFormat($doc);

    $issueService = new IssueService();
    $ret = $issueService->addComment($subTaskIssueKey, $comment);
            
    print_r($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'add Comment Failed : ' . $e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
    $issueService = new IssueService();
    
    $param = [
         'startAt' => 0, 
         'maxResults' => 3,
         'expand' => 'renderedBody',
    ];
   
    $comments = $issueService->getComments($issueKey, $param);

    // $comments->comments is a real array of comment
    foreach ($comments->comments as $comment){
        var_dump(["id" => comment->id, "self" => $comment->self]);
    }  
    
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'get Comment Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
    $issueService = new IssueService();
    
    $param = [
         'startAt' => 0, 
         'maxResults' => 3,
         'expand' => 'renderedBody',
    ];
    $commentId = 13805;

    $comments = $issueService->getComment($issueKey, $commentId, $param);

    var_dump($comments);

} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'get Comment Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {
    $commentId = 12345;

    $issueService = new IssueService();

    $ret = $issueService->deleteComment($issueKey, $commentId);

} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Delete comment Failed : '.$e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;
use JiraCloud\Issue\Comment;

$issueKey = 'TEST-879';

try {
    $commentId = 12345;

    $issueService = new IssueService();
        
    $comment = new Comment();

    $code =<<<CODE
# This program adds two numbers
num1 = 1.5
num2 = 6.3

# Add two numbers
sum = num1 + num2

# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
CODE;

    $doc = (new Document())
        ->heading(2)            // header level 1, can have child blocks (needs to be closed with `->end()`)
            ->text('h2')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
        ->end()                 // closes `heading` node
        ->heading(3)            // header level 2
            ->text('h3')        // simple unstyled text
        ->end()                 // closes `heading` node
        ->heading(4)
            ->text('heading 4')
        ->end()
        ->paragraph()           // paragraph
            ->text('also support heading.') // simple unstyled text
        ->end()                 // closes `paragraph` node
        ->codeblock('python')
            ->text($code)
        ->end()
        ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
            ->text('we’re ')    // simple unstyled text
            ->strong('support') // text node embedding a `strong` mark
            ->text(' ')         // simple unstyled text
            ->em('markdown')    // text node embedding a `em` mark
            ->text('. ')        // simple unstyled text
            ->underline('like') // text node embedding a `underline` mark
            ->text(' this.')    // simple unstyled text
            ->text(' date=' . date("Y-m-d H:i:s"))
        ->end()                 // closes `paragraph` node
    ;

    $comment->setBodyByAtlassianDocumentFormat($doc);

    $issueService = new IssueService();
    $ret = $issueService->updateComment($issueKey, $comment_id, $comment);

} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Update comment Failed : '.$e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\Issue\Transition;
use JiraCloud\JiraException;

$issueKey = 'TEST-879';

try {			
    $transition = new Transition();
    $transition->setTransitionName('In Progress');
    
    $doc = (new Document())
                ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
                    ->text('Issue ')    // simple unstyled text
                    ->strong(' status') // text node embedding a `strong` mark
                    ->text(' ')         // simple unstyled text
                    ->text(' changed ')    // text node embedding a `em` mark
                    ->text('. ')        // simple unstyled text
                    ->underline('by') // text node embedding a `underline` mark
                    ->em(' REST API.')    // simple unstyled text
                ->end()                 // closes `paragraph` node
            ;

    $comment = new AtlassianDocumentFormat($doc);
    
    $transition->setCommentBody($comment);

    $issueService = new IssueService();
    $issueService->transition($issueKey, $transition);
    
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(FALSE, 'add Comment Failed : ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$jql = 'project not in (TEST)  and assignee = currentUser() and status in (Resolved, closed)';

try {
    $issueService = new IssueService();

    $ret = $issueService->search($jql);
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;
use JiraCloud\Issue\JqlFunction;

// Searches for issues that are linked to an issue. You can restrict the search to links of a particular type. 
try {
    $linkedIssue = JqlFunction::linkedIssues('TEST-01', 'IN', 'is blocked by');

    $issueService = new IssueService();

    $ret = $issueService->search($linkedIssue->expression);

    var_dump($ret);
} catch (JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}

// Searches for epics and subtasks. If the issue is not an epic, the search returns all subtasks for the issue. 
try {
    $linkedIssue = JqlFunction::linkedissue('TEST-01');

    $issueService = new IssueService();

    $ret = $issueService->search($linkedIssue->expression);

    var_dump($ret);
} catch (JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$jql = 'project not in (TEST)  and assignee = currentUser() and status in (Resolved, closed)';

try {
    $issueService = new IssueService();

    $pagination = -1;
  
    $startAt = 0;	//the index of the first issue to return (0-based)    
    $maxResult = 3;	// the maximum number of issues to return (defaults to 50). 
    $totalCount = -1;	// the number of issues to return
  
    // first fetch
    $ret = $issueService->search($jql, $startAt, $maxResult);
    $totalCount = $ret->total;
  	
    // do something with fetched data
    foreach ($ret->issues as $issue) {
        print (sprintf('%s %s \n', $issue->key, $issue->fields->summary));
    }
  	
    // fetch remained data
    $page = $totalCount / $maxResult;

    for ($startAt = 1; $startAt < $page; $startAt++) {
        $ret = $issueService->search($jql, $startAt * $maxResult, $maxResult);

        print ('\nPaging $startAt\n');
        print ('-------------------\n');
        foreach ($ret->issues as $issue) {
            print (sprintf('%s %s \n', $issue->key, $issue->fields->summary));
        }
    }     
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\JqlQuery;
use JiraCloud\JiraException;
use JiraCloud\Issue\JqlFunction;

try {
    $jql = new JqlQuery();

    $jql->setProject('TEST')
        ->setType('Bug')
        ->setStatus('In Progress')
        ->setAssignee(JqlFunction::currentUser())
        ->setCustomField('My Custom Field', 'value')
        ->addIsNotNullExpression('due');

    $issueService = new IssueService();

    $ret = $issueService->search($jql->getQuery());

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-316';

try {
    $issueService = new IssueService();

    $rils = $issueService->getRemoteIssueLink($issueKey);
        
    // rils is array of RemoteIssueLink classes
    var_dump($rils);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, $e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\Issue\RemoteIssueLink;
use JiraCloud\JiraException;

$issueKey = 'TEST-316';

try {
    $issueService = new IssueService();

    $ril = new RemoteIssueLink();

    $ril->setUrl('http://www.mycompany.com/support?id=1')
        ->setTitle('Remote Link Title')
        ->setRelationship('causes')
        ->setSummary('Crazy customer support issue')
    ;

    $rils = $issueService->createOrUpdateRemoteIssueLink($issueKey, $ril);

    // rils is array of RemoteIssueLink classes
    var_dump($rils);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\TimeTracking;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';

try {
    $issueService = new IssueService();
    
    // get issue's time tracking info
    $ret = $issueService->getTimeTracking($this->issueKey);
    var_dump($ret);
    
    $timeTracking = new TimeTracking;

    $timeTracking->setOriginalEstimate('3w 4d 6h');
    $timeTracking->setRemainingEstimate('1w 2d 3h');
    
    // add time tracking
    $ret = $issueService->timeTracking($this->issueKey, $timeTracking);
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}



DateInterval;
use DateTime;
use DH\Adf\Node\Block\Document;
use JiraCloud\ADF\AtlassianDocumentFormat;
use PHPUnit\Framework\TestCase;
use JiraCloud\Issue\IssueService;
use JiraCloud\Issue\Worklog;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';

try {
    $workLog = new Worklog();
    
    $doc = (new Document())
                ->heading(1)            // header level 1, can have child blocks (needs to be closed with `->end()`)
                    ->text('h1')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
                ->end()                 // closes `heading` node
                ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
                    ->text('we’re ')    // simple unstyled text
                    ->strong('support') // text node embedding a `strong` mark
                    ->text(' ')         // simple unstyled text
                    ->em('markdown')    // text node embedding a `em` mark
                    ->text('. ')        // simple unstyled text
                    ->underline('like') // text node embedding a `underline` mark
                    ->text(' this.')    // simple unstyled text
                ->end()                 // closes `paragraph` node
                ->heading(2)            // header level 2
                    ->text('h2')        // simple unstyled text
                ->end()                 // closes `heading` node
                ->heading(3)
                    ->text('heading 3')
                ->end()
                ->paragraph()           // paragraph
                    ->text('also support heading.') // simple unstyled text
                ->end()                 // closes `paragraph` node
                ->codeblock('php')
                    ->text($code)
                ->end()
            ;

    $comment = new AtlassianDocumentFormat($doc);

    $startedAt = (new DateTime('NOW'))
        ->add(DateInterval::createFromDateString('-1 hour -27 minute'));

    $workLog->setComment($comment)
        ->setStarted($startedAt)
        ->setTimeSpent('1d 2h 3m');

    $issueService = new IssueService();

    $ret = $issueService->addWorklog($issueKey, $workLog);

    $workLogid = $ret->{'id'};

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}



DateInterval;
use DateTime;
use DH\Adf\Node\Block\Document;
use JiraCloud\ADF\AtlassianDocumentFormat;
use PHPUnit\Framework\TestCase;
use JiraCloud\Issue\IssueService;
use JiraCloud\Issue\Worklog;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';
$workLogid = '12345';

try {
    $workLog = new Worklog();

    $doc = (new Document())
                ->heading(1)            // header level 1, can have child blocks (needs to be closed with `->end()`)
                ->text('h1')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
                ->end()                 // closes `heading` node
                ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
                    ->text('I’did ')    // simple unstyled text
                    ->strong('edit') // text node embedding a `strong` mark
                    ->text(' ')         // simple unstyled text
                    ->em('previous')    // text node embedding a `em` mark
                    ->text(' ')        // simple unstyled text
                    ->underline('worklog') // text node embedding a `underline` mark
                    ->text(' here.')    // simple unstyled text
                ->end()                 // closes `paragraph` node
                ->heading(2)            // header level 2
                 ->text('h2')        // simple unstyled text
                ->end()                 // closes `heading` node
                ->heading(3)
                 ->text('heading 3')
                ->end()
                ->paragraph()           // paragraph
                 ->text('also support heading.') // simple unstyled text
                ->end()                 // closes `paragraph` node
            ;

    $comment = new AtlassianDocumentFormat($doc);

    $workLog->setComment($comment)
        ->setTimeSpent('2d 7h 5m');

    $issueService = new IssueService();

    $ret = $issueService->editWorklog($issueKey, $workLog, $workLogid);

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Edit worklog Failed : '.$e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';

try {
    $issueService = new IssueService();
    
    // get issue's all worklog
    $worklogs = $issueService->getWorklog($issueKey)->getWorklogs();
    var_dump($worklogs);
    
    // get worklog by id
    $wlId = 12345;
    $wl = $issueService->getWorklogById($issueKey, $wlId);
    var_dump($wl);
    
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}



JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';

try {
    $issueService = new IssueService();
    
    // watcher's id
    $watcher = 'lesstif';
    
    $issueService->addWatcher($issueKey, $watcher);
    
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'add watcher Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';

try {
    $issueService = new IssueService();
    
    // watcher's id
    $watcher = 'lesstif';
    
    $issueService->removeWatcher($issueKey, $watcher);
    
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'add watcher Failed : '.$e->getMessage());
}


JiraCloud\Issue\IssueService;
use JiraCloud\Issue\Notify;
use JiraCloud\JiraException;

$issueKey = 'TEST-961';

try {
    $issueService = new IssueService();

    $noti = new Notify();

    $noti->setSubject('notify test')
        ->setTextBody('notify test text body')
        ->setHtmlBody('<h1>notify</h1>test html body')
        ->sendToAssignee(true)
        ->sendToWatchers(true)
        ->sendToUser('lesstif', true)
        ->sendToGroup('temp-group')
    ;

    $issueService->notify($issueKey, $noti);
    
} catch (JiraCloud\JiraException $e) {
    $this->assertTrue(false, 'Issue notify Failed : '.$e->getMessage());
}


JiraCloud\IssueLink\IssueLink;
use JiraCloud\IssueLink\IssueLinkService;
use JiraCloud\JiraException;

try {
    $doc = (new Document())
                ->heading(1)            // header level 1, can have child blocks (needs to be closed with `->end()`)
                    ->text('h1')        // simple unstyled text, cannot have child blocks (no `->end()` needed)
                ->end()                 // closes `heading` node
                ->paragraph()           // paragraph, can have child blocks (needs to be closed with `->end()`)
                    ->text('Issue Link ')    // simple unstyled text
                    ->strong('By ') // text node embedding a `strong` mark
                    ->text(' REST ')         // simple unstyled text
                    ->em('API')
                ->end()                 // closes `paragraph` node
             ;

    $comment = new AtlassianDocumentFormat($doc);

    $il = new IssueLink();

    $inwardKey = 'TEST-162';
    $outwardKey = 'ST-3';
    
    $il->setInwardIssueByKey($inwardKey)
        ->setOutwardIssueByKey($outwardKey)
        ->setLinkTypeName('Duplicate' )
        ->setCommentAsADF($comment)
    ;

    $ils = new IssueLinkService();

    $ret = $ils->addIssueLink($il);
    
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\IssueLink\IssueLinkService;
use JiraCloud\JiraException;

try {
    $ils = new IssueLinkService();

    $ret = $ils->getIssueLinkTypes();
    
    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    // create new user
    $user = $us->create([
            'name'=>'charlie',
            'password' => 'abracadabra',
            'emailAddress' => '[email protected]',
            'displayName' => 'Charlie of Atlassian',
        ]);

    var_dump($user);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    $user = $us->get(['username' => 'lesstif']);

    var_dump($user);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    $paramArray = [
        'username' => '.', // get all users. 
        'startAt' => 0,
        'maxResults' => 1000,
        '


JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    $paramArray = [
        //'username' => null,
        'project' => 'TEST',
        //'issueKey' => 'TEST-1',
        'startAt' => 0,
        'maxResults' => 50, //max 1000
        //'actionDescriptorId' => 1,
    ];

    $users = $us->findAssignableUsers($paramArray);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    $paramArray = [
      'query' => 'is watcher of TEST',
    ];

    $users = $us->findUsersByQuery($paramArray);
    var_dump($users);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    $paramArray = ['username' => '[email protected]'];

    $users = $us->deleteUser($paramArray);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\User\UserService;

try {
    $us = new UserService();

    $paramArray = ['username' => '[email protected]'];

    // create new user
    $user = [
            'name'=>'charli',
            'password' => 'abracada',
            'emailAddress' => '[email protected]',
            'displayName' => 'Charli of Atlassian',
        ];

    $updatedUser = $us->update($paramArray, $user)

    var_dump($updatedUser);

} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\Group\GroupService;
use JiraCloud\Group\Group;

try {
    $g = new Group();

    $g->name = 'Test group for REST API';

    $gs = new GroupService();
    $ret = $gs->createGroup($g);

    var_dump($ret);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\Group\GroupService;

try {
   $queryParam = [
        'groupname' => 'Test group for REST API',
        ' users in the group
    foreach($ret->values as $user) {
        print_r($user);
    }
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\Group\GroupService;

try {
    $groupName  = '한글 그룹 name';
    $userName = 'lesstif';

    $gs = new GroupService();

    $ret = $gs->addUserToGroup($groupName, $userName);

    // print current state of the group.
    print_r($ret);

} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\JiraException;
use JiraCloud\Group\GroupService;

try {
    $groupName  = '한글 그룹 name';
    $userName = 'lesstif';

    $gs = new GroupService();

    $gs->removeUserFromGroup($groupName, $userName);

} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Priority\PriorityService;
use JiraCloud\JiraException;

try {
    $ps = new PriorityService();

    $p = $ps->getAll();
	
    var_dump($p);
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Priority\PriorityService;
use JiraCloud\JiraException;

try {
    $ps = new PriorityService();

    $p = $ps->get(1);
	
    var_dump($p);
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Attachment\AttachmentService;
use JiraCloud\JiraException;

try {
    $attachmentId = 12345;

    $atts = new AttachmentService();
    $att = $atts->get($attachmentId);

    var_dump($att);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Attachment\AttachmentService;
use JiraCloud\JiraException;

try {
    $attachmentId = 12345;
    $outDir = 'attachment_dir';
    
    $atts = new AttachmentService();
    $att = $atts->get($attachmentId, $outDir, $overwrite = true);

    var_dump($att);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Attachment\AttachmentService;
use JiraCloud\JiraException;

try {
    $attachmentId = 12345;

    $atts = new AttachmentService();

    $atts->remove($attachmentId);
} catch (JiraCloud\JiraException $e) {
	print('Error Occurred! ' . $e->getMessage());
}


JiraCloud\Issue\Version;
use JiraCloud\Project\ProjectService;
use JiraCloud\Version\VersionService;
use JiraCloud\JiraException;

try {
    $projectService = new ProjectService();
    $project = $projectService->get('TEST');

    $versionService = new VersionService();

    $version = new Version();

    $version->setName('1.0.0')
            ->setDescription('Generated by script')
            ->setReleased(false)
            ->setStartDateAsDateTime(new \DateTime())
            ->setReleaseDateAsDateTime((new \DateTime())->add(date_interval_create_from_date_string('2 weeks 3 days')))
            ->setProjectId($project->id)
            ;

    $res = $versionService->create($version);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Version\VersionService;
use JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $versionService = new VersionService();
    $projectService = new ProjectService();

    $ver = $projectService->getVersion('TEST', '1.0.0');

    // update version
    $ver->setName($ver->name . ' Updated name')
        ->setDescription($ver->description . ' Updated description')
        ->setReleased(false)
        ->setStartDateAsDateTime(new \DateTime())
        ->setReleaseDateAsDateTime((new \DateTime())->add(date_interval_create_from_date_string('1 months 3 days')))
        ;

    $res = $versionService->update($ver);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Version\VersionService;
use JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $versionService = new VersionService();
    $projectService = new ProjectService();

    $version = $projectService->getVersion('TEST', '1.0.0');

    $res = $versionService->delete($version);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Version\VersionService;
use JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $versionService = new VersionService();
    $projectService = new ProjectService();

    $version = $projectService->getVersion('TEST', '1.0.0');

    $res = $versionService->getRelatedIssues($version);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Version\VersionService;
use JiraCloud\Project\ProjectService;
use JiraCloud\JiraException;

try {
    $versionService = new VersionService();
    $projectService = new ProjectService();

    $version = $projectService->getVersion('TEST', '1.0.0');

    $res = $versionService->getUnresolvedIssues($version);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Component\ComponentService;
use JiraCloud\Issue\Version;
use JiraCloud\Project\Component;
use JiraCloud\JiraException;

try {
    $componentService = new ComponentService();
    
    $component = new Component();
    $component->setName('my component')
              ->setDescription('Generated by script')
              ->setProjectKey('TEST');

    $res = $componentService->create($component);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Component\ComponentService;
use JiraCloud\Issue\Version;
use JiraCloud\Project\Component;
use JiraCloud\JiraException;

try {
    $componentService = new ComponentService();
    
    $component = $componentService->get(10000); // component-id
    $component->setName($component->name . ' Updated name')
              ->setDescription($component->description . ' Updated descrption')
              ->setLeadUserName($component->lead->key);  // bug in jira api

    $res = $componentService->update($component);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Component\ComponentService;
use JiraCloud\Issue\Version;
use JiraCloud\Project\Component;
use JiraCloud\JiraException;

try {
    $componentService = new ComponentService();
    
    $component = $componentService->get(10000); // component-id

    $res = $componentService->delete($component);

    var_dump($res);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Board\BoardService;

try {
  $board_service = new BoardService();
  $board = $board_service->getBoardList();
  
  var_dump($board);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Board\BoardService;

try {
  $board_service = new BoardService();
  $board_id = 1;
  $board = $board_service->getBoard($board_id);
  
  var_dump($board);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



JiraCloud\Board\BoardService;

try {
  $board_service = new BoardService();
  $board_id = 1;
  $issues = $board_service->getBoardIssues($board_id, [
    'maxResults' => 500,
    'jql' => urlencode('status != Closed'),
  ]);
  
  foreach ($issues as $issue) {
    var_dump($issue);
  }
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



{
  $board_service = new JiraCloud\Board\BoardService();
  $board_id = 1;
  $epics = $board_service->getBoardEpics($board_id, [
    'maxResults' => 500,
  ]);
  
  foreach ($epics as $epic) {
    var_dump($epic);
  }
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



{
  $epic_service = new JiraCloud\Epic\EpicService();
  $epic_id = 1;
  $epic = $epic_service->getEpic($epic_id);
  
  var_dump($epic);
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}



{
  $epic_service = new JiraCloud\Epic\EpicService();
  $epic_id = 1;
  $issues = $epic_service->getEpicIssues($epic_id, [
    'maxResults' => 500,
    'jql' => urlencode('status != Closed'),
  ]);
  
  foreach ($issues as $issue) {
    var_dump($issue);
  }
} catch (JiraCloud\JiraException $e) {
    print('Error Occurred! ' . $e->getMessage());
}

 sh
   curl -sS https://getcomposer.org/installer | php
   
 sh
   php composer.phar 
sh
   php composer.phar install