How to use REST API to add issue links in JIRA issues

Still need help?

The Atlassian Community is here for you.

Ask the community

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"
                   }
                }
             }
          ]
       }
    }

    (info) 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"
                   }
                }
             }
          ]
       }
    }

    (info) Replace the values accordingly based on your configuration

    (info) 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:


Last modified on Mar 21, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.