Create and link work items between different Jira Cloud sites
Platform Notice: Cloud Only - This article only applies to Atlassian apps on the cloud platform.
Summary
Currently, you cannot connect two separate Jira Cloud sites using application links (app links) if they share the same the server ID, allowing you to link existing work items between the sites.
Solution
Sample automation rule steps
Step 1
Make use of any automation trigger. In the example below, we will use the manual trigger.
Step 2
We will utilize the “Send web request” action. This step requires careful configuration using the following parameters:
Create an API token for your site that will be used within the automation
Choose the destination explicitly
The rule runs on the source site, while the new work item must be created on the destination site. {{baseUrl}} resolves to the Jira instance running the rule; it is not a variable for the other site.
Use POST with this URL, replacing destination-site with the destination site’s hostname:
https://destination-site.atlassian.net/rest/api/3/issue
Use credentials that have Browse projects and Create issues permissions in the destination space. Keep the existing Delay execution of subsequent rule actions until we've received a response for this web request option so that the next action can use the newly created work item's key.
Headers - Accept: application/json, Authorization: Basic <base64-token>
Remember to replace <base64-token> by your generated base64 encoded string at the 1st step from this post.
HTTP Method - POST
Web request body - Custom data
{
"fields": {
"project": { "key": "AP" },
"summary": "{{issue.summary}}",
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "{{issue.description}}"
}
]
}
]
},
"issuetype": { "name": "Task" }
}
}
The asJsonString JSON function can also be used for text inserted into the JSON body. It escapes special characters and includes surrounding quotation marks automatically, so do not add additional quotes around the smart value.
Example: "summary": {{issue.summary.asJsonString}}
Step 3
Add a log action and add the web response smart value to check which work item got created on the destination site.
{{webResponse.body.key}}
Step 4
Add a send web request action again to use the send web request action and make use of the endpoint shared below, and the custom data to create the link between both work items.
Create a link from the original work item
To add a remote link on the original work item, configure the action with HTTP method POST and the following URL:
{{baseUrl}}/rest/api/3/issue/{{issue.key}}/remotelink
In the payload’s object.url, use the destination hostname and the key returned by Step 2:
"url": "https://destination-site.atlassian.net/browse/{{webResponse.body.key}}"
This POST request creates or updates a remote link on the work item specified in the request URL. (The later GET example in this article only reads existing remote links.) Verify both link directions separately; one request does not create a link on both sites automatically. Issue linking must be active, and the request credentials must have Browse projects and Link issues permissions for the work item receiving the link.
Payload (body)
{
"application": {
"name": "Application Link Name",
"type": "com.atlassian.jira"
},
"relationship": "is blocked by",
"object": {
"summary":"{{issue.summary}}",
"title": "{{issue.key}}",
"url": "https://{{url}}.atlassian.net/browse/{{issuekey}}"
},
"createReciprocalLink": true,
"globalId": "appId={{appID}}&issueId={{issueID}}"
}To get the APP ID of the destination site, make use of the below API call and check from the browser to get the APP ID eg: ( FP-18 is a work item).
https://<myinstance.atlassian.net/rest/api/3/issue/FP-18/remotelink>
Before performing the above step, make sure the manual link is working by using the app link; if not, we might not be able to get the APP ID.
Was this helpful?