How to use REST API to add issue links in JIRA issues
Platform Notice: Cloud and Data Center - This article applies equally to both cloud and data center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Purpose
This article explains the JSON data needed to add issue links to a JIRA issue. We can use issueLink Rest API. This can also be done either when creating the issue or when editing the issue.
Solution 1
Use issueLink REST operation
- Run POST rest/api/2/issueLink
Example: Here issueLink.json exist in same location where we invoke issueLink REST operation using curl command.
$ cat issueLink.json { "type": { "name": "Duplicate" }, "inwardIssue": { "key": "SCRUM5-6" }, "outwardIssue": { "key": "SCRUM5-5" }, "comment": { "body": "Linked related issue!" } } $ curl -u "username:password" -X POST -H "Content-Type: application/json" -d @issueLink.json http://localhost:8080/rest/api/2/issueLink
Solution 2
Creating an issue
- Make sure Linked Issues is added to the appropriate Create Issue screen
Run POST /rest/api/2/issue using the following JSON data
{ "fields":{ "project":{ "key":"TEST" }, "summary":"test bug summary", "description":"test bug description", "issuetype":{ "name":"Bug" }, "priority":{ "name":"Major" } }, "update":{ "issuelinks":[ { "add":{ "type":{ "name":"Blocks", "inward":"is blocked by", "outward":"blocks" }, "outwardIssue":{ "key":"TEST-1" } } } ] } }
Replace the values accordingly based on your configuration
Editing an issue
- Make sure Linked Issues is added to the appropriate Edit Issue screen
Run PUT /rest/api/2/issue/{issueIdOrKey} using the following JSON data
{ "update":{ "issuelinks":[ { "add":{ "type":{ "name":"Blocks", "inward":"is blocked by", "outward":"blocks" }, "outwardIssue":{ "key":"TEST-1" } } } ] } }
Replace the values accordingly based on your configuration
It is also possible to reference issues by id. To do this, replace "key" with "id" and use the corresponding database issue id.
It's currently not possible to add multiple issue links in a single REST call. The following Bugs have been raised for this:
- Server: JRASERVER-66329 - Getting issue details... STATUS
- Cloud: JRACLOUD-65583 - Getting issue details... STATUS