Purpose


On this KB, we will see how to associate a Salesforce Record using an API call.

The Association is made using this URL:

<BASE-URL>/rest/api/2/issue/<KEY>/properties/com.servicerocket.jira.cloud.issue.salesforce.associations

This is the Jira endpoint that stores the association (entity property)

There is a known limitation with Jira entity properties. This is due to a storage hard limit imposed by Atlassian Jira Cloud (maximum of 32Kb of data per issue).

This roughly translates to 300 associations at most, so we are setting a recommended maximum here.

More information about this limitation can be read here:

Entity properties


Answer


Please use the following URL:

<BASE-URL>/rest/api/2/issue/<KEY>/properties/com.servicerocket.jira.cloud.issue.salesforce.associations

Replace the <BASE-URL> with your Jira Cloud base-url and <KEY> with your JIRA-issue-key.


The following is a sample of the JSON payload to migrate/store the associations (for 1 associations):

{
    "associations": {
        "<SOID>": {
            "son": "Case",
            "viewOnly": false,
            "autoPush": true,
            "autoPull": true
         }
    },
    "ids": "<SOID>>",
    "types": "Case"
}

Replace <SOID> with the Salesforce Id to be associated.


For multiple associations (2 associations), you can use the following JSON body:

{
    "associations": {
        "<SOID1>": {
            "son": "Case",
            "viewOnly": false,
            "autoPush": true,
            "autoPull": true
        },
        "<SOID2>": {
            "son": "Case",
            "viewOnly": true,
            "autoPush": false,
            "autoPull": false
        }
    },
    "ids": "<SOID1> <SOID2>",
    "types": "Case"
}

For the following example we will use the Postman app

https://www.postman.com/

use a PUT request (with postman)

Authenticate to your Jira Cloud using API token

https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/

You can create the API token in your Jira cloud instance using this URL

https://id.atlassian.com/manage-profile/security/api-tokens

Run a PUT request to <BASE-URL>/rest/api/2/issue/<KEY>/properties/com.servicerocket.jira.cloud.issue.salesforce.associations with the following payload (replace SOID with Salesforce ID)

In the postman Body section add the following code:

{
    "associations": {
        "<SOID>": {
            "son": "Case",
            "viewOnly": false,
            "autoPush": true,
            "autoPull": true
         }
    },
    "ids": "<SOID>>",
    "types": "Case"
}

Next select JSON from the drop down menu

Access the <BASE-URL>/rest/api/2/issue/<KEY>/properties/com.servicerocket.jira.cloud.issue.salesforce.associations on your browser and you should be seeing the associations, similar to the image bellow:



One thing to note is that the associations may not appear immediately on the UI.  This is because cache is at play here.  The associations are stored on the property-entry, but the associations will only appear on the UI after around 20 minutes.  This is normal and expected, so it may take a little while for end-users to see it on the Jira issue.