PHP code example of mi-lopez / jira-php

1. Go to this page and download the library: Download mi-lopez/jira-php 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/ */

    

mi-lopez / jira-php example snippets


$client = Jira::client('USERNAME', 'PASSWORD', 'jira.domain.com');

$result = $client->issues()->search();

echo $result['issues'][0]['key']; // KEY-1000

$client->attachments()->get(id: '1000');

[
    'self' => 'https://www.example.com/jira/rest/api/2.0/attachments/10000',
    'filename' => 'picture.jpg',
    'author' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'avatarUrls' => [
            '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
            '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
            '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
            '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
        ],
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'created' => '2019-02-09T10:08:20.478+0000',
    'size' => 23123,
    'mimeType' => 'image/jpeg',
    'content' => 'https://www.example.com/jira/attachments/10000',
    'thumbnail' => 'https://www.example.com/jira/secure/thumbnail/10000',
];

$client->attachments()->remove(id: '1000');

null

$attachment = $client->attachments()->get(id: '1000');

$client->attachments()->download(url: $attachment['content']);

$client->customers()->create(
    body: [
        'fullName' => 'name',
        'email' => '[email protected]',
    ],
);

[
    'name' => 'fred',
    'key' => 'fred',
    'emailAddress' => '[email protected]',
    'displayName' => 'Fred F. User',
    'active' => true,
    'timeZone' => 'Australia/Sydney',
    '_links' => [
        'jiraRest' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'avatarUrls' => [
            '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
            '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
            '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
            '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
        ],
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
    ],
];

$client->groups()->create(
    body: [
        'name' => 'group name',
    ],
);

[
    'name' => 'jira-administrators',
    'self' => 'https://www.example.com/jira/rest/api/2/group?groupname=jira-administrators',
    'users' => [
        'size' => 1,
        'items' => [
            [
                'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                'name' => 'fred',
                'displayName' => 'Fred F. User',
                'active' => false,
            ],
        ],
        'max-results' => 50,
        'start-index' => 0,
        'end-index' => 0,
    ],
    'expand' => 'users',
];

$client->groups()->remove(
    query: [
        'name' => 'group name',
    ],
);

null

$client->groups()->getUsers(
    query: [
        'groupname' => 'group name',
    ],
);

[
    'self' => 'https://example.com/rest/api/2/group/member?groupname=admin&startAt=2&maxResults=2',
    'nextPage' => 'https://example.com/rest/api/2/group/member?groupname=admin&startAt=4&maxResults=2',
    'maxResults' => 2,
    'startAt' => 3,
    'total' => 5,
    'isLast' => false,
    'values' => [
        [
            'self' => 'https://example/jira/rest/api/2/user?username=fred',
            'name' => 'Fred',
            'key' => 'fred',
            'emailAddress' => '[email protected]',
            'avatarUrls' => [],
            'displayName' => 'Fred',
            'active' => true,
            'timeZone' => 'Australia/Sydney',
        ],
        [
            'self' => 'https://example/jira/rest/api/2/user?username=barney',
            'name' => 'Barney',
            'key' => 'barney',
            'emailAddress' => '[email protected]',
            'avatarUrls' => [],
            'displayName' => 'Barney',
            'active' => false,
            'timeZone' => 'Australia/Sydney',
        ],
    ],
];

$client->groups()->addUser(
    query: [
        'groupname' => 'group name',
    ],
    body: [
        'name' => 'user name',
    ],
);

[
    'name' => 'example',
    'self' => 'url',
    'users' => [],
    'expand' => '',
];

$client->groups()->removeUser(
    query: [
        'groupname' => 'group name',
        'username' => 'user name',
    ],
);

null

$client
    ->issues()
    ->create(body: [...]);

[
    'id' => '10000',
    'key' => 'TST-24',
    'self' => 'https://www.example.com/jira/rest/api/2/issue/10000',
];

$client
    ->issues()
    ->bulk(body: [
        [...],
        [...],
        [...]
    ]);

[
    'issues' => [
        [
            'id' => '10000',
            'key' => 'TST-24',
            'self' => 'https://www.example.com/jira/rest/api/2/issue/10000',
        ],
        [
            'id' => '10001',
            'key' => 'TST-25',
            'self' => 'https://www.example.com/jira/rest/api/2/issue/10001',
        ],
    ],
    'errors' => [],
];

$client->issues()->get(id: 'KEY-1000', query: [...]);

[
    'expand' => 'renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations',
    'id' => '10002',
    'self' => 'https://www.example.com/jira/rest/api/2/issue/10002',
    'key' => 'EX-1',
    'fields' => [
        'watcher' => [
            'self' => 'https://www.example.com/jira/rest/api/2/issue/EX-1/watchers',
            'isWatching' => false,
            'watchCount' => 1,
            'watchers' => [
                [
                    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                    'name' => 'fred',
                    'displayName' => 'Fred F. User',
                    'active' => false,
                ],
            ],
        ],
        'attachment' => [
            [
                'self' => 'https://www.example.com/jira/rest/api/2.0/attachments/10000',
                'filename' => 'picture.jpg',
                'author' => [
                    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                    'name' => 'fred',
                    'avatarUrls' => [
                        '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
                        '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
                        '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
                        '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
                    ],
                    'displayName' => 'Fred F. User',
                    'active' => false,
                ],
                'created' => '2019-02-09T10:08:20.478+0000',
                'size' => 23123,
                'mimeType' => 'image/jpeg',
                'content' => 'https://www.example.com/jira/attachments/10000',
                'thumbnail' => 'https://www.example.com/jira/secure/thumbnail/10000',
            ],
        ],
        'sub-tasks' => [
            [
                'id' => '10000',
                'type' => [
                    'id' => '10000',
                    'name' => '',
                    'inward' => 'Parent',
                    'outward' => 'Sub-task',
                ],
                'outwardIssue' => [
                    'id' => '10003',
                    'key' => 'EX-2',
                    'self' => 'https://www.example.com/jira/rest/api/2/issue/EX-2',
                    'fields' => [
                        'status' => [
                            'iconUrl' => 'https://www.example.com/jira/images/icons/statuses/open.png',
                            'name' => 'Open',
                        ],
                    ],
                ],
            ],
        ],
        'description' => 'example bug report',
        'project' => [
            'self' => 'https://www.example.com/jira/rest/api/2/project/EX',
            'id' => '10000',
            'key' => 'EX',
            'name' => 'Example',
            'avatarUrls' => [
                '48x48' => 'https://www.example.com/jira/secure/projectavatar?size=large&pid=10000',
                '24x24' => 'https://www.example.com/jira/secure/projectavatar?size=small&pid=10000',
                '16x16' => 'https://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10000',
                '32x32' => 'https://www.example.com/jira/secure/projectavatar?size=medium&pid=10000',
            ],
            'projectCategory' => [
                'self' => 'https://www.example.com/jira/rest/api/2/projectCategory/10000',
                'id' => '10000',
                'name' => 'FIRST',
                'description' => 'First Project Category',
            ],
        ],
        'comment' => [
            [
                'self' => 'https://www.example.com/jira/rest/api/2/issue/10010/comment/10000',
                'id' => '10000',
                'author' => [
                    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                    'name' => 'fred',
                    'displayName' => 'Fred F. User',
                    'active' => false,
                ],
                'body' => 'Lorem ipsum dolor sit amet.',
                'updateAuthor' => [
                    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                    'name' => 'fred',
                    'displayName' => 'Fred F. User',
                    'active' => false,
                ],
                'created' => '2019-02-09T10:08:20.180+0000',
                'updated' => '2019-02-09T10:08:20.181+0000',
                'visibility' => [
                    'type' => 'role',
                    'value' => 'Administrators',
                ],
            ],
        ],
        'issuelinks' => [
            [
                'id' => '10001',
                'type' => [
                    'id' => '10000',
                    'name' => 'Dependent',
                    'inward' => 'depends on',
                    'outward' => 'is depended by',
                ],
                'outwardIssue' => [
                    'id' => '10004L',
                    'key' => 'PRJ-2',
                    'self' => 'https://www.example.com/jira/rest/api/2/issue/PRJ-2',
                    'fields' => [
                        'status' => [
                            'iconUrl' => 'https://www.example.com/jira//images/icons/statuses/open.png',
                            'name' => 'Open',
                        ],
                    ],
                ],
            ],
            [
                'id' => '10002',
                'type' => [
                    'id' => '10000',
                    'name' => 'Dependent',
                    'inward' => 'depends on',
                    'outward' => 'is depended by',
                ],
                'inwardIssue' => [
                    'id' => '10004',
                    'key' => 'PRJ-3',
                    'self' => 'https://www.example.com/jira/rest/api/2/issue/PRJ-3',
                    'fields' => [
                        'status' => [
                            'iconUrl' => 'https://www.example.com/jira//images/icons/statuses/open.png',
                            'name' => 'Open',
                        ],
                    ],
                ],
            ],
        ],
        'worklog' => [
            [
                'self' => 'https://www.example.com/jira/rest/api/2/issue/10010/worklog/10000',
                'author' => [
                    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                    'name' => 'fred',
                    'displayName' => 'Fred F. User',
                    'active' => false,
                ],
                'updateAuthor' => [
                    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                    'name' => 'fred',
                    'displayName' => 'Fred F. User',
                    'active' => false,
                ],
                'comment' => 'I did some work here.',
                'updated' => '2019-02-09T10:08:20.486+0000',
                'visibility' => [
                    'type' => 'group',
                    'value' => 'jira-developers',
                ],
                'started' => '2019-02-09T10:08:20.486+0000',
                'timeSpent' => '3h 20m',
                'timeSpentSeconds' => 12000,
                'id' => '100028',
                'issueId' => '10002',
            ],
        ],
        'updated' => 1,
        'timetracking' => [
            'originalEstimate' => '10m',
            'remainingEstimate' => '3m',
            'timeSpent' => '6m',
            'originalEstimateSeconds' => 600,
            'remainingEstimateSeconds' => 200,
            'timeSpentSeconds' => 400,
        ],
    ],
    'names' => [
        'watcher' => 'watcher',
        'attachment' => 'attachment',
        'sub-tasks' => 'sub-tasks',
        'description' => 'description',
        'project' => 'project',
        'comment' => 'comment',
        'issuelinks' => 'issuelinks',
        'worklog' => 'worklog',
        'updated' => 'updated',
        'timetracking' => 'timetracking',
    ],
    'schema' => [],
];

$client->issues()->delete(id: 'KEY-1000', query: [...]);

null

$client->issues()->edit(id: 'KEY-1000', body: [...], query: [...]);

null

$client->issues()->archive(id: 'KEY-1000');

null

$client->issues()->assign(id: 'KEY-1000', body: [...]);

null

$client->issues()->getComments(id: 'KEY-1000', query: [...]);

[
    'startAt' => 0,
    'maxResults' => 1,
    'total' => 1,
    'comments' => [
        [
            'self' => 'https://www.example.com/jira/rest/api/2/issue/10010/comment/10000',
            'id' => '10000',
            'author' => [
                'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                'name' => 'fred',
                'displayName' => 'Fred F. User',
                'active' => false,
            ],
            'body' => 'Lorem ipsum dolor sit amet.',
            'updateAuthor' => [
                'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
                'name' => 'fred',
                'displayName' => 'Fred F. User',
                'active' => false,
            ],
            'created' => '2019-02-09T10:08:20.180+0000',
            'updated' => '2019-02-09T10:08:20.181+0000',
            'visibility' => [
                'type' => 'role',
                'value' => 'Administrators',
            ],
        ],
    ],
];

$client->issues()->addComment(id: 'KEY-1000', body: [...], query: [...]);

[
    'self' => 'https://www.example.com/jira/rest/api/2/issue/10010/comment/10000',
    'id' => '10000',
    'author' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'body' => 'Lorem ipsum dolor sit amet.',
    'updateAuthor' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'created' => '2019-02-09T10:08:20.180+0000',
    'updated' => '2019-02-09T10:08:20.181+0000',
    'visibility' => [
        'type' => 'role',
        'value' => 'Administrators',
    ],
];

$client->issues()->updateComment(id: 'KEY-1000', commentId: '10000', body: [...], query: [...]);

[
    'self' => 'https://www.example.com/jira/rest/api/2/issue/10010/comment/10000',
    'id' => '10000',
    'author' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'body' => 'Lorem ipsum dolor sit amet.',
    'updateAuthor' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'created' => '2019-02-09T10:08:20.180+0000',
    'updated' => '2019-02-09T10:08:20.181+0000',
    'visibility' => [
        'type' => 'role',
        'value' => 'Administrators',
    ],
];

$client->issues()->deleteComment(id: 'KEY-1000', commentId: '10000', query: [...]);

null

$client->issues()->getComment(id: 'KEY-1000', commentId: '10000', query: [...]);

[
    'self' => 'https://www.example.com/jira/rest/api/2/issue/10010/comment/10000',
    'id' => '10000',
    'author' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'body' => 'Lorem ipsum dolor sit amet.',
    'updateAuthor' => [
        'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        'name' => 'fred',
        'displayName' => 'Fred F. User',
        'active' => false,
    ],
    'created' => '2019-02-09T10:08:20.180+0000',
    'updated' => '2019-02-09T10:08:20.181+0000',
    'visibility' => [
        'type' => 'role',
        'value' => 'Administrators',
    ],
];

$client->issues()->getTransitions(id: 'KEY-1000', query: [...]);

[
    'expand' => 'transitions',
    'transitions' => [
        [
            'id' => '2',
            'name' => 'Close Issue',
            'to' => [
                'self' => 'https://localhost:8090/jira/rest/api/2.0/status/10000',
                'description' => 'The issue is currently being worked on.',
                'iconUrl' => 'https://localhost:8090/jira/images/icons/progress.gif',
                'name' => 'In Progress',
                'id' => '10000',
                'statusCategory' => [
                    'self' => 'https://localhost:8090/jira/rest/api/2.0/statuscategory/1',
                    'id' => 1,
                    'key' => 'in-flight',
                    'colorName' => 'yellow',
                    'name' => 'In Progress',
                ],
            ],
            'fields' => [
                'summary' => [
                    'name' => 'Closed',
                'id' => '5',
                'statusCategory' => [
                    'self' => 'https://localhost:8090/jira/rest/api/2.0/statuscategory/9',
                    'id' => 9,
                    'key' => 'completed',
                    'colorName' => 'green',
                ],
            ],
            'fields' => [
                'summary' => [
                    '

$client->issues()->doTransition(id: 'KEY-1000', body: [...], query: [...]);

null

$client->issues()->attach(id: 'KEY-1000', body: [...]);

[
    [
        'self' => 'https://www.example.com/jira/rest/api/2.0/attachments/10000',
        'filename' => 'picture.jpg',
        'author' => [
            'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
            'name' => 'fred',
            'avatarUrls' => [
                '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
                '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
                '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
                '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
            ],
            'displayName' => 'Fred F. User',
            'active' => false,
        ],
        'created' => '2019-02-09T10:08:20.478+0000',
        'size' => 23123,
        'mimeType' => 'image/jpeg',
        'content' => 'https://www.example.com/jira/attachments/10000',
        'thumbnail' => 'https://www.example.com/jira/secure/thumbnail/10000',
    ],
    [
        'self' => 'https://www.example.com/jira/rest/api/2.0/attachments/10001',
        'filename' => 'dbeuglog.txt',
        'author' => [
            'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
            'name' => 'fred',
            'avatarUrls' => [
                '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
                '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
                '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
                '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
            ],
            'displayName' => 'Fred F. User',
            'active' => false,
        ],
        'created' => '2019-02-09T10:08:20.478+0000',
        'size' => 2460,
        'mimeType' => 'text/plain',
        'content' => 'https://www.example.com/jira/attachments/10001',
        'thumbnail' => 'https://www.example.com/jira/secure/thumbnail/10002',
    ],
];

$client->issues()->search(query: [...]);

[
    'expand' => 'names,schema',
    'startAt' => 0,
    'maxResults' => 50,
    'total' => 1,
    'issues' => [
        [
            'expand' => '',
            'id' => '10001',
            'self' => 'https://www.example.com/jira/rest/api/2/issue/10001',
            'key' => 'HSP-1',
        ],
    ],
];

$client->requests()->create(body: [...]);

[
    '_expands' => ['participant', 'status', 'sla', 'requestType', 'serviceDesk'],
    'issueId' => '107001',
    'issueKey' => 'HELPDESK-1',
    'requestTypeId' => '25',
    'serviceDeskId' => '10',
    'createdDate' => [
        'iso8601' => '2015-10-08T14:42:00+0700',
        'jira' => '2015-10-08T14:42:00.000+0700',
        'friendly' => 'Monday 14:42 PM',
        'epochMillis' => 1444290120000,
    ],
    'reporter' => [
        'name' => 'fred',
        'key' => 'fred',
        'emailAddress' => '[email protected]',
        'displayName' => 'Fred F. User',
        'active' => true,
        'timeZone' => 'Australia/Sydney',
        '_links' => [
            'jiraRest' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
            'avatarUrls' => [
                '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
                '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
                '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
                '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
            ],
            'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
        ],
    ],
    'requestFieldValues' => [
        [
            'fieldId' => 'summary',
            'label' => 'What do you need?',
            'value' => 'Request JSD help via REST',
        ],
        [
            'fieldId' => 'description',
            'label' => 'Why do you need this?',
            'value' => 'I need a new mouse for my Mac',
        ],
    ],
    'currentStatus' => [
        'status' => 'Waiting for Support',
        'statusDate' => [
            'iso8601' => '2015-10-08T14:01:00+0700',
            'jira' => '2015-10-08T14:01:00.000+0700',
            'friendly' => 'Today 14:01 PM',
            'epochMillis' => 1444287660000,
        ],
    ],
    '_links' => [
        'jiraRest' => 'https://host:port/context/rest/api/2/issue/107001',
        'web' => 'https://host:port/context/servicedesk/customer/portal/10/HELPDESK-1',
        'self' => 'https://host:port/context/rest/servicedeskapi/request/107001',
    ],
];

$client->users()->update(body: [...]);

[
    'self' => 'https://www.example.com/jira/rest/api/2/user/charlie',
    'key' => 'charlie',
    'name' => 'charlie',
    'emailAddress' => '[email protected]',
    'displayName' => 'Charlie of Atlassian',
];

$client->users()->create(body: [...]);

[
    'self' => 'https://www.example.com/jira/rest/api/2/user/charlie',
    'key' => 'charlie',
    'name' => 'charlie',
    'emailAddress' => '[email protected]',
    'displayName' => 'Charlie of Atlassian',
];

$client->users()->remove(query: [...]);

null

$client->users()->get(query: [...]);

[
    'self' => 'https://www.example.com/jira/rest/api/2/user?username=fred',
    'name' => 'fred',
    'emailAddress' => '[email protected]',
    'avatarUrls' => [
        '48x48' => 'https://www.example.com/jira/secure/useravatar?size=large&ownerId=fred',
        '24x24' => 'https://www.example.com/jira/secure/useravatar?size=small&ownerId=fred',
        '16x16' => 'https://www.example.com/jira/secure/useravatar?size=xsmall&ownerId=fred',
        '32x32' => 'https://www.example.com/jira/secure/useravatar?size=medium&ownerId=fred',
    ],
    'displayName' => 'Fred F. User',
    'active' => true,
    'timeZone' => 'Australia/Sydney',
    'groups' => [
        'size' => 3,
        'items' => [
            [
                'name' => 'jira-user',
                'self' => 'https://www.example.com/jira/rest/api/2/group?groupname=jira-user',
            ],
            [
                'name' => 'jira-admin',
                'self' => 'https://www.example.com/jira/rest/api/2/group?groupname=jira-admin',
            ],
            [
                'name' => 'important',
                'self' => 'https://www.example.com/jira/rest/api/2/group?groupname=important',
            ],
        ],
    ],
    'applicationRoles' => [
        'size' => 1,
        'items' => [],
    ],
    'expand' => 'groups,applicationRoles',
];
bash
composer