How to link a Confluence page on a Jira Cloud Issue via Rest API
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
The purpose of this article is to demonstrate the linking of Confluence page with a Jira issue via Rest API
Environment
Jira Cloud
Confluence Cloud
Solution
- The Confluence instance is integrated with Jira as an Application Link. Hence, please note down the appID of the system Confluence link that is connected to the Jira instance:
https://<instance name>.atlassian.net/rest/applinks/3.0/applinks
Example:
[
{
"id": "ecdb7ab5-b22c-3519-abd2-907a7abcdefg",
"name": "System Confluence",
"displayUrl": "https://<instance name>.atlassian.net/wiki",
"rpcUrl": "https://<instance name>.atlassian.net/wiki",
"type": "confluence",
"system": true,
"primary": true
},
Here is the appID is ecdb7ab5-b22c-3519-abd2-907a7abcdefg
If there are multiple application links connected to the Jira instance and you wish to use the System Confluence link for the page ↔ issue linking, then look for the Applink with the name "System Confluence"
- Note the page ID of the Confluence page to be linked to the Jira issue. The Confluence pageID can be obtained in the Address bar upon opening a Confluence page:
Example:
https://<instance name>.atlassian.net/wiki/spaces/TEST/pages/426141234/Test+page
Here the pageID is 426141234
- Use the below API call to link the Confluence page to a Jira issue:
curl --request POST \
--url 'https://<instance-name>.atlassian.net/rest/api/3/issue/<jira-issue>/remotelink' \
--user 'email:API Token' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"globalId": "appId=<Conf app-id>&pageId=<Page ID>",
"application": {
"type": "com.atlassian.confluence",
"name": "System Confluence"
},
"relationship": "Wiki Page",
"object": {
"url": "https://bnktest.atlassian.net/wiki/pages/viewpage.action?pageId=<page ID>",
"title": "Wiki Page",
"icon": {},
"status": {
"icon": {}
}
}
}'
In the above call, please replace:
a) <instance-name> with instance URL of your Atlassian Cloud instance
b) <jira-issue> with the Jira issue key that the Confluence page is linked on.
c) email:API Token with your Atlassian account email ID and the API token
d) <Conf app-id> with the Confluence application link ID obtained from Step 1
e) <Page ID> with the Confluence page ID obtained from Step 2
The below response indicates that a page is successfully linked:
{"id":10062,"self":"https://<instance name>.atlassian.net/rest/api/3/issue/<jira-issue>/remotelink/10062"}