If you want to interact with Jira On-premise(Server or Data Center) instead of Cloud, use this repository.
- PHP >= 8.1
- php JsonMapper
- phpdotenv
- adf-tools
Download and Install PHP Composer.
curl -sS https://getcomposer.org/installer | phpNext, run the Composer command to install the latest version of php jira rest client.
php composer.phar require lesstif/jira-cloud-restapi:^1.0
or add the following to your composer.json file.
{ "require": { "lesstif/jira-cloud-restapi": "^1.0" } }Then run Composer's install or update commands to complete installation.
php composer.phar install
After installing, you need to require Composer's autoloader:
require'vendor/autoload.php';
Laravel: Once installed, if you are not using automatic package discovery, then you need to register the JiraCloud\JiraCloudApiServiceProvider service provider in your config/app.php.
you can choose loads environment variables either 'dotenv' or 'array'.
copy .env.example file to .env on your project root.
JIRAAPI_V3_HOST='https://your-jira.atlassian.net'
JIRAAPI_V3_USER='jira-username'
JIRAAPI_V3_PERSONAL_ACCESS_TOKEN='your-access-token-here'## to enable session cookie authorization# JIRAAPI_V3_COOKIE_AUTH_ENABLED=true# JIRAAPI_V3_COOKIE_FILE=storage/jira-cookie.txt## if you are behind a proxy, add proxy settings
JIRAAPI_V3_PROXY_SERVER='your-proxy-server'
JIRAAPI_V3_PROXY_PORT='proxy-port'
JIRAAPI_V3_PROXY_USER='proxy-username'
JIRAAPI_V3_PROXY_PASSWORD='proxy-password'CAUTION this library not fully supported JIRA REST API V3 yet.
create Service class with ArrayConfiguration parameter.
useJiraCloud\Configuration\ArrayConfiguration;
useJiraCloud\Issue\IssueService;
$iss = newIssueService(newArrayConfiguration(
[
'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',
]
));- Create Project
- Update Project
- Delete Project
- Get Project Info
- Get All Project list
- Get Project Components
- Get Project Type
- Get Project Version
- Get Project Roles
- Get Project Role
- Get Issue Info
- Create Issue
- Create Issue - bulk
- Create Sub Task
- Create Issue using REST API V3
- Add Attachment
- Update issue
- Change assignee
- Remove issue
- Perform a transition on an issue
- Perform an advanced search, using the JQL
- Remote Issue Link
- Issue time tracking
- Add worklog in Issue
- Edit worklog in Issue
- Get Issue worklog
- Add watcher to Issue
- Remove watcher from Issue
- Send a notification to the recipients
Create a new project.
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\Project\Project;
useJiraCloud\JiraException;
try {
$p = newProject();
$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 = newProjectService();
$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());
}Update a project. Only none null values sent in JSON will be updated in the project.
Values available for the assigneeType field are: 'PROJECT_LEAD' and 'UNASSIGNED'.
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\Project\Project;
useJiraCloud\JiraException;
try {
$p = newProject();
$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 = newProjectService();
$pj = $proj->updateProject($p, 'EX');
var_dump($pj);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Deletes a project.
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$proj = newProjectService();
$pj = $proj->deleteProject('EX');
var_dump($pj);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$proj = newProjectService();
$p = $proj->get('TEST');
var_dump($p); } catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$proj = newProjectService();
$prjs = $proj->getAllProjects();
foreach ($prjsas$p) {
echosprintf('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());
}See Jira API reference (Get project components)
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$proj = newProjectService();
$prjs = $proj->getAllProjects();
// Extract and show Project Components for every Jira Projectforeach ($prjsas$p) {
var_export($proj->getProjectComponents($p->id));
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}See Jira API reference (get all types)
See Jira API reference (get type)
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$proj = newProjectService();
// get all project type$prjtyps = $proj->getProjectTypes();
foreach ($prjtypsas$pt) {
var_dump($pt);
}
// get specific project type.$pt = $proj->getProjectType('software');
var_dump($pt);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}get all project's versions.
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$proj = newProjectService();
$vers = $proj->getVersions('TEST');
foreach ($versas$v) {
// $v is JiraCloud\Issue\Versionvar_dump($v);
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}or get paginated project's versions.
<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$param = [
'startAt' => 0,
'maxResults' => 10,
'orderBy' => 'name',
//'expand' => null,
];
$proj = newProjectService();
$vers = $proj->getVersionsPagenated('TEST', $param);
foreach ($versas$v) {
// $v is JiraCloud\Issue\Versionvar_dump($v);
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$projectService = newProjectService();
// return project roles list. $ret = $projectService->getProjectRoles('TEST'); var_dump($ret);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$projectService = newProjectService();
// return project role data with reporter assigned. $ret = $projectService->getProjectRoles('TEST', '1'); var_dump($ret);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Field\Field;
useJiraCloud\Field\FieldService;
useJiraCloud\JiraException;
try {
$fieldService = newFieldService();
// return custom field only. $ret = $fieldService->getAllFields(Field::CUSTOM); var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Field\Field;
useJiraCloud\Field\FieldService;
useJiraCloud\JiraException;
try {
$field = newField();
$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 = newFieldService();
$ret = $fieldService->create($field);
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'Field Create Failed : '.$e->getMessage());
}If you need a list of custom field types(ex. com.atlassian.jira.plugin.system.customfieldtypes:grouppicker) , check out Get All Field list.
Returns a full representation of the issue for the given issue key.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
try {
$issueService = newIssueService();
$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());
}You can access the custom field associated with issue through $issue->fields->customFields array or through direct custom field id variables(Ex: $issue->fields->customfield_10300).
All Jira v3 API users must use the Atlassian Document Format (ADF) for comment and description fields. It's represents rich text stored in Atlassian products, so very complicated.
For that reason, I used the amazing adf-tools create by DamienHarper.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\IssueField;
useJiraCloud\JiraException;
useDH\Adf\Node\Block\Document;
useJiraCloud\ADF\AtlassianDocumentFormat;
try {
$issueField = newIssueField();
$code =<<<CODE<?php\$i = 123;\$a = ['hello', 'world', ];var_dump([\$i => \$a]);CODE;
$doc = (newDocument())
->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 = newAtlassianDocumentFormat($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 = newIssueService();
$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());
}If you want to set custom field, you can call the addCustomField function with custom field id and value as parameters.
try {
$issueField = newIssueField();
$doc = (newDocument()) ->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 = newAtlassianDocumentFormat($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 = newIssueService();
$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());
}Currently, not tested for all custom field types.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\IssueField;
useJiraCloud\JiraException;
useJiraCloud\ADF\ADFMarkType;
useJiraCloud\ADF\AtlassianDocumentFormat;
try {
$issueFieldOne = newIssueField();
$doc = (newDocument()) ->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 = newAtlassianDocumentFormat($doc);
$issueFieldOne->setProjectKey('TEST')
->setSummary('something\'s wrong')
->setPriorityNameAsString('Critical')
->setIssueTypeAsString('Bug')
->setDescription($descV3);
$issueFieldTwo = newIssueField();
$doc2 = (newDocument()) ->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 = newAtlassianDocumentFormat(doc2);
$issueFieldTwo->setProjectKey('TEST')
->setSummary('something else is wrong')
->setPriorityNameAsString('Critical')
->setIssueTypeAsString('Bug')
->setDescription($desc2);
$issueService = newIssueService();
$ret = $issueService->createMultiple([$issueFieldOne, $issueFieldTwo]);
//If success, returns an array of the created issuesvar_dump($ret);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Creating a sub-task is similar to creating a regular issue, with two important method calls:
->setIssueTypeAsString('Sub-task')
->setParentKeyOrId($issueKeyOrId)for example
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\IssueField;
useJiraCloud\JiraException;
useJiraCloud\ADF\ADFMarkType;
useJiraCloud\ADF\AtlassianDocumentFormat;
try {
$issueField = newIssueField();
$doc = (newDocument()) ->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 = newAtlassianDocumentFormat(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 = newIssueService();
$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());
}REST API V3' description field is complicated.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\IssueFieldV3;
useJiraCloud\Issue\DescriptionV3;
useJiraCloud\JiraException;
try {
$issueField = newIssueFieldV3();
$paraDesc =<<< DESCFull description for issue- order list 1- order list 2-- sub order list 1-- sub order list 1- order list 3 DESC;
$descV3 = newDescriptionV3();
$descV3->addDescriptionContent('paragraph', $paraDesc);
$issueField->setProjectKey('TEST')
->setSummary("something's wrong")
->setAssigneeAccountId('user-account-id-here')
->setPriorityNameAsString('Critical')
->setIssueTypeAsString('Bug')
->setDescriptionV3($descV3)
;
$issueService = newIssueService();
$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());
}If you want to set custom field, you can call the addCustomField function with custom field id and value as parameters.
try {
$issueField = newIssueField();
$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 = newIssueService();
$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());
}Currently, not tested for all custom field types.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$issueService = newIssueService();
// 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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\IssueField;
useJiraCloud\JiraException;
useJiraCloud\ADF\ADFMarkType;
useJiraCloud\ADF\AtlassianDocumentFormat;
$issueKey = 'TEST-879';
try { $issueField = newIssueField(true);
$doc = (newDocument()) ->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 = newAtlassianDocumentFormat(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 = newIssueService();
// 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());
}If you want to change the custom field type when updating an issue, you can call the addCustomField function just as you did for creating issue.
This function is a convenient wrapper for add or remove label in the issue.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
try {
$issueKey = 'TEST-123';
$issueService = newIssueService();
$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());
}This function is a convenient wrapper for add or remove fix version in the issue.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
try {
$issueKey = 'TEST-123';
$issueService = newIssueService();
$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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$issueService = newIssueService();
// 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());
}REST API V3(JIRA Cloud) users must use changeAssigneeByAccountId method with accountId.
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$issueService = newIssueService();
$accountId = 'usre-account-id';
$ret = $issueService->changeAssigneeByAccountId($issueKey, $accountId);
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(FALSE, 'Change Assignee Failed : ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$issueService = newIssueService();
$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());
}Not working at this time.!
<?phprequire'vendor/autoload.php';
useDH\Adf\Node\Block\Document;
useJiraCloud\ADF\AtlassianDocumentFormat;
useJiraCloud\Issue\Comment;
useJiraCloud\Issue\IssueService;
$issueKey = 'TEST-879';
try { $comment = newComment();
$code =<<<CODE<?php\$i = 123;\$a = ['hello', 'world', ];var_dump([\$i => \$a]);CODE;
$doc = (newDocument())
->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 = newIssueService();
$ret = $issueService->addComment($subTaskIssueKey, $comment);
print_r($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(FALSE, 'add Comment Failed : ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$issueService = newIssueService();
$param = [
'startAt' => 0, 'maxResults' => 3,
'expand' => 'renderedBody',
];
$comments = $issueService->getComments($issueKey, $param);
// $comments->comments is a real array of commentforeach ($comments->commentsas$comment){
var_dump(["id" => comment->id, "self" => $comment->self]);
} } catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'get Comment Failed : '.$e->getMessage());
}get comment by comment id
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$issueService = newIssueService();
$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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try {
$commentId = 12345;
$issueService = newIssueService();
$ret = $issueService->deleteComment($issueKey, $commentId);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'Delete comment Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
useJiraCloud\Issue\Comment;
$issueKey = 'TEST-879';
try {
$commentId = 12345;
$issueService = newIssueService();
$comment = newComment();
$code =<<<CODE# This program adds two numbersnum1 = 1.5num2 = 6.3# Add two numberssum = num1 + num2# Display the sumprint('The sum of {0} and {1} is {2}'.format(num1, num2, sum))CODE;
$doc = (newDocument())
->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 = newIssueService();
$ret = $issueService->updateComment($issueKey, $comment_id, $comment);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'Update comment Failed : '.$e->getMessage());
}Note: this library uses goal status names instead of transition names.
So, if you want to change issue status to 'Some Status',
you should pass that status name to setTransitionName
i.e. $transition->setTransitionName('Some Status')
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\Transition;
useJiraCloud\JiraException;
$issueKey = 'TEST-879';
try { $transition = newTransition();
$transition->setTransitionName('In Progress');
$doc = (newDocument())
->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 = newAtlassianDocumentFormat($doc);
$transition->setCommentBody($comment);
$issueService = newIssueService();
$issueService->transition($issueKey, $transition);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(FALSE, 'add Comment Failed : ' . $e->getMessage());
}Note: If you are JIRA with local language profiles, you must use setUntranslatedName instead of setTransitionName.
i.e. $transition->setUntranslatedName('Done')
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$jql = 'project not in (TEST) and assignee = currentUser() and status in (Resolved, closed)';
try {
$issueService = newIssueService();
$ret = $issueService->search($jql);
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
useJiraCloud\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 = newIssueService();
$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 = newIssueService();
$ret = $issueService->search($linkedIssue->expression);
var_dump($ret);
} catch (JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$jql = 'project not in (TEST) and assignee = currentUser() and status in (Resolved, closed)';
try {
$issueService = newIssueService();
$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 dataforeach ($ret->issuesas$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->issuesas$issue) {
print (sprintf('%s %s \n', $issue->key, $issue->fields->summary));
}
} } catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}If you're not familiar JQL then you can use convenience JqlQuery class.
JqlFunction class can be used to add jql functions calls to query.
You can find the names of almost all fields, functions, keywords and operators
defined as constants in JqlQuery and static methods in JqlFunciton classes.
For more info see the Jira docs (link above).
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\JqlQuery;
useJiraCloud\JiraException;
useJiraCloud\Issue\JqlFunction;
try {
$jql = newJqlQuery();
$jql->setProject('TEST')
->setType('Bug')
->setStatus('In Progress')
->setAssignee(JqlFunction::currentUser())
->setCustomField('My Custom Field', 'value')
->addIsNotNullExpression('due');
$issueService = newIssueService();
$ret = $issueService->search($jql->getQuery());
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'testSearch Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-316';
try {
$issueService = newIssueService();
$rils = $issueService->getRemoteIssueLink($issueKey);
// rils is array of RemoteIssueLink classesvar_dump($rils);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\RemoteIssueLink;
useJiraCloud\JiraException;
$issueKey = 'TEST-316';
try {
$issueService = newIssueService();
$ril = newRemoteIssueLink();
$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 classesvar_dump($rils);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}This methods use get issue and edit issue methods internally.
See Jira API reference (get issue)
See Jira API reference (edit issue)
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\TimeTracking;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
try {
$issueService = newIssueService();
// get issue's time tracking info$ret = $issueService->getTimeTracking($this->issueKey);
var_dump($ret);
$timeTracking = newTimeTracking;
$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());
}<?phprequire'vendor/autoload.php';
useDateInterval;
useDateTime;
useDH\Adf\Node\Block\Document;
useJiraCloud\ADF\AtlassianDocumentFormat;
usePHPUnit\Framework\TestCase;
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\Worklog;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
try {
$workLog = newWorklog();
$doc = (newDocument())
->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 = newAtlassianDocumentFormat($doc);
$startedAt = (newDateTime('NOW'))
->add(DateInterval::createFromDateString('-1 hour -27 minute'));
$workLog->setComment($comment)
->setStarted($startedAt)
->setTimeSpent('1d 2h 3m');
$issueService = newIssueService();
$ret = $issueService->addWorklog($issueKey, $workLog);
$workLogid = $ret->{'id'};
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'Create Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useDateInterval;
useDateTime;
useDH\Adf\Node\Block\Document;
useJiraCloud\ADF\AtlassianDocumentFormat;
usePHPUnit\Framework\TestCase;
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\Worklog;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
$workLogid = '12345';
try {
$workLog = newWorklog();
$doc = (newDocument())
->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 = newAtlassianDocumentFormat($doc);
$workLog->setComment($comment)
->setTimeSpent('2d 7h 5m');
$issueService = newIssueService();
$ret = $issueService->editWorklog($issueKey, $workLog, $workLogid);
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'Edit worklog Failed : '.$e->getMessage());
}See Jira API reference (get full issue worklog)
See Jira API reference (get worklog by id)
<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
try {
$issueService = newIssueService();
// 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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
try {
$issueService = newIssueService();
// watcher's id$watcher = 'lesstif';
$issueService->addWatcher($issueKey, $watcher);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'add watcher Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
try {
$issueService = newIssueService();
// watcher's id$watcher = 'lesstif';
$issueService->removeWatcher($issueKey, $watcher);
} catch (JiraCloud\JiraException$e) {
$this->assertTrue(false, 'add watcher Failed : '.$e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\IssueService;
useJiraCloud\Issue\Notify;
useJiraCloud\JiraException;
$issueKey = 'TEST-961';
try {
$issueService = newIssueService();
$noti = newNotify();
$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());
}The Link Issue Resource provides functionality to manage issue links.
<?phprequire'vendor/autoload.php';
useJiraCloud\IssueLink\IssueLink;
useJiraCloud\IssueLink\IssueLinkService;
useJiraCloud\JiraException;
try {
$doc = (newDocument())
->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 = newAtlassianDocumentFormat($doc);
$il = newIssueLink();
$inwardKey = 'TEST-162';
$outwardKey = 'ST-3';
$il->setInwardIssueByKey($inwardKey)
->setOutwardIssueByKey($outwardKey)
->setLinkTypeName('Duplicate' )
->setCommentAsADF($comment)
;
$ils = newIssueLinkService();
$ret = $ils->addIssueLink($il);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Rest resource to retrieve a list of issue link types.
<?phprequire'vendor/autoload.php';
useJiraCloud\IssueLink\IssueLinkService;
useJiraCloud\JiraException;
try {
$ils = newIssueLinkService();
$ret = $ils->getIssueLinkTypes();
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Create user. By default created user will not be notified with email. If password field is not set then password will be randomly generated.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
// create new user$user = $us->create([
'name'=>'charlie',
'password' => 'abracadabra',
'emailAddress' => 'charlie@atlassian.com',
'displayName' => 'Charlie of Atlassian',
]);
var_dump($user);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Returns a user.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
$user = $us->get(['username' => 'lesstif']);
var_dump($user);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Returns a list of users that match the search string and/or property.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
$paramArray = [
'username' => '.', // get all users. 'startAt' => 0,
'maxResults' => 1000,
'includeInactive' => true,
//'property' => '*',
];
// get the user info.$users = $us->findUsers($paramArray);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Returns a list of users that match the search string.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
$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());
}Returns a list of users that match the search string.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
$paramArray = [
'query' => 'is watcher of TEST',
];
$users = $us->findUsersByQuery($paramArray);
var_dump($users);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Removes user.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
$paramArray = ['username' => 'user@example.com'];
$users = $us->deleteUser($paramArray);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Updates user.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\User\UserService;
try {
$us = newUserService();
$paramArray = ['username' => 'user@example.com'];
// create new user$user = [
'name'=>'charli',
'password' => 'abracada',
'emailAddress' => 'charli@atlassian.com',
'displayName' => 'Charli of Atlassian',
];
$updatedUser = $us->update($paramArray, $user)
var_dump($updatedUser);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Create new group.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\Group\GroupService;
useJiraCloud\Group\Group;
try {
$g = newGroup();
$g->name = 'Test group for REST API';
$gs = newGroupService();
$ret = $gs->createGroup($g);
var_dump($ret);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}returns a paginated list of users who are members of the specified group and its subgroups.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\Group\GroupService;
try {
$queryParam = [
'groupname' => 'Test group for REST API',
'includeInactiveUsers' => true, // default false'startAt' => 0,
'maxResults' => 50,
];
$gs = newGroupService();
$ret = $gs->getMembers($queryParam);
// print all users in the groupforeach($ret->valuesas$user) {
print_r($user);
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}add user to given group.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\Group\GroupService;
try {
$groupName = '한글 그룹 name';
$userName = 'lesstif';
$gs = newGroupService();
$ret = $gs->addUserToGroup($groupName, $userName);
// print current state of the group.print_r($ret);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Removes given user from a group.
<?phprequire'vendor/autoload.php';
useJiraCloud\JiraException;
useJiraCloud\Group\GroupService;
try {
$groupName = '한글 그룹 name';
$userName = 'lesstif';
$gs = newGroupService();
$gs->removeUserFromGroup($groupName, $userName);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Priority\PriorityService;
useJiraCloud\JiraException;
try {
$ps = newPriorityService();
$p = $ps->getAll();
var_dump($p);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Priority\PriorityService;
useJiraCloud\JiraException;
try {
$ps = newPriorityService();
$p = $ps->get(1);
var_dump($p);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Attachment\AttachmentService;
useJiraCloud\JiraException;
try {
$attachmentId = 12345;
$atts = newAttachmentService();
$att = $atts->get($attachmentId);
var_dump($att);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Gets the attachment information and saves the attachment into the outDir directory.
<?phprequire'vendor/autoload.php';
useJiraCloud\Attachment\AttachmentService;
useJiraCloud\JiraException;
try {
$attachmentId = 12345;
$outDir = 'attachment_dir';
$atts = newAttachmentService();
$att = $atts->get($attachmentId, $outDir, $overwrite = true);
var_dump($att);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Attachment\AttachmentService;
useJiraCloud\JiraException;
try {
$attachmentId = 12345;
$atts = newAttachmentService();
$atts->remove($attachmentId);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Issue\Version;
useJiraCloud\Project\ProjectService;
useJiraCloud\Version\VersionService;
useJiraCloud\JiraException;
try {
$projectService = newProjectService();
$project = $projectService->get('TEST');
$versionService = newVersionService();
$version = newVersion();
$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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Version\VersionService;
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$versionService = newVersionService();
$projectService = newProjectService();
$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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Version\VersionService;
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$versionService = newVersionService();
$projectService = newProjectService();
$version = $projectService->getVersion('TEST', '1.0.0');
$res = $versionService->delete($version);
var_dump($res);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Version\VersionService;
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$versionService = newVersionService();
$projectService = newProjectService();
$version = $projectService->getVersion('TEST', '1.0.0');
$res = $versionService->getRelatedIssues($version);
var_dump($res);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Version\VersionService;
useJiraCloud\Project\ProjectService;
useJiraCloud\JiraException;
try {
$versionService = newVersionService();
$projectService = newProjectService();
$version = $projectService->getVersion('TEST', '1.0.0');
$res = $versionService->getUnresolvedIssues($version);
var_dump($res);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Component\ComponentService;
useJiraCloud\Issue\Version;
useJiraCloud\Project\Component;
useJiraCloud\JiraException;
try {
$componentService = newComponentService();
$component = newComponent();
$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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Component\ComponentService;
useJiraCloud\Issue\Version;
useJiraCloud\Project\Component;
useJiraCloud\JiraException;
try {
$componentService = newComponentService();
$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());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Component\ComponentService;
useJiraCloud\Issue\Version;
useJiraCloud\Project\Component;
useJiraCloud\JiraException;
try {
$componentService = newComponentService();
$component = $componentService->get(10000); // component-id$res = $componentService->delete($component);
var_dump($res);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Board\BoardService;
try {
$board_service = newBoardService();
$board = $board_service->getBoardList();
var_dump($board);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Board\BoardService;
try {
$board_service = newBoardService();
$board_id = 1;
$board = $board_service->getBoard($board_id);
var_dump($board);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
useJiraCloud\Board\BoardService;
try {
$board_service = newBoardService();
$board_id = 1;
$issues = $board_service->getBoardIssues($board_id, [
'maxResults' => 500,
'jql' => urlencode('status != Closed'),
]);
foreach ($issuesas$issue) {
var_dump($issue);
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
try {
$board_service = newJiraCloud\Board\BoardService();
$board_id = 1;
$epics = $board_service->getBoardEpics($board_id, [
'maxResults' => 500,
]);
foreach ($epicsas$epic) {
var_dump($epic);
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
try {
$epic_service = newJiraCloud\Epic\EpicService();
$epic_id = 1;
$epic = $epic_service->getEpic($epic_id);
var_dump($epic);
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}<?phprequire'vendor/autoload.php';
try {
$epic_service = newJiraCloud\Epic\EpicService();
$epic_id = 1;
$issues = $epic_service->getEpicIssues($epic_id, [
'maxResults' => 500,
'jql' => urlencode('status != Closed'),
]);
foreach ($issuesas$issue) {
var_dump($issue);
}
} catch (JiraCloud\JiraException$e) {
print('Error Occurred! ' . $e->getMessage());
}Apache V2 License
