How to use REST API to add remote links in JIRA issues?

Still need help?

The Atlassian Community is here for you.

Ask the community

Purpose

This article explains the JSON data structure needed to add remote links , including link to confluence pages, to an existent JIRA issue using the remoteLink Rest API .

To create a Web Link to an issue you will need the URL to be linked and the Link Text (title) to be displayed for the Web Link , this information will be used to build the JSON blob used on to run the POST /rest/api/2/issue/{issueIdOrKey}/remotelink command , below is an example for this command :

  • Example: Here remoteLink.json exist in same location where we invoke remoteLink REST operation using curl command.

    $ cat remoteLink.json
    {
      "object": {
        "url": "https://www.atlassian.com/software/jira",
        "title": "Jira Software Page"
      }
    }
    
    $ curl -u "username:password" -XPOST -H "Content-Type: application/json" -d @remoteLink.json 'http://localhost:8080/rest/api/latest/issue/SAMPLE-1/remotelink'

(lightbulb)More information on the JSON fields can be found at Using fields in Remote Issue Links .

To create a Confluence link you will need the same information as for the Web Link , plus the information of the Application for the link and to generate the a globalId for the page to be linked to .

  • The Application in this case will be confluence and its declaration for all links is static as per provided example JSON 
  • The globalId is a string composed of the application ID (appId=) inside Jira that refers to its application link connection with confluence and the confluence page ID (pageId=) .
    • The application ID can be retrieved from the URL of the application link edit page , by following the below steps
      • Go to Administration > Applications > Application Links and click on the Edit (pencil icon) icon on the Confluence configuration line

      • On the new loaded page you can retrieve the application ID from its URL as per below example:
    • The Confluence page ID can be retrieved inside confluence using the KB How to get Confluence page ID 


This information will be used to build the JSON blob used on to run the POST /rest/api/2/issue/{issueIdOrKey}/remotelink command , below is an example for this command :

  • Example: Here remoteLink.json exist in same location where we invoke remoteLink REST operation using curl command.

    $ cat remoteLink.json
    {
      "globalId": "appId=43d21959-661d-36dc-a836-debca302edd7&pageId=98320",
      "application": {
        "type": "com.atlassian.confluence",
        "name": "Confluence"
      },
      "object": {
        "url": "http://localhost:8090/pages/viewpage.action?pageId=98320",
        "title": "Wiki Page"
      }
    }
    
    $ curl -u "username:password" -XPOST -H "Content-Type: application/json" -d @remoteLink.json 'http://localhost:8080/rest/api/latest/issue/SAMPLE-1/remotelink'




Last modified on Jan 2, 2024

Was this helpful?

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