Skip to main content
Skip table of contents

Set Connected item values when created issues with Jira REST API

Objective

Learn how to set the value of Elements Connected items when creating issue on a Jira Service Management project programmatically using Jira REST API.

Jira Service Management only.

This method only works for Connected items configured on Jira Service Management project.
It is not yet possible to apply it on Jira Software or a Jira Work Management projects.

See it in action

In our example, we use Postman (an API platform for building and using APIs) to create an Issue with Jira REST API.

We have configured two connected items on our request type:

  • "Phone Brand", of type Select list. This item displays a list of phone brands fetched from a SQL database.
  • "Phones of brand" of type Read only. This item display all phones of the brand selected in "Phone brand". It is hidden on the JSM portal

As "Phones of brand" is hidden, we don't have to set its value using the REST API. We will the the value of "Phone brand" only, Elements Connect will automatically set the value of "Phones on brand" when the issue is created.



Tutorial

Prerequisites

  • Elements Connect is installed on your Jira Cloud instance
  • Jira Service Management is active on your instance
  • At least 1 connected item is configured and associated to a request type

Find the required information

You need the following information from your Jira configuration:

  • the IDs of the Connected item(s) configured on the request
  • the IDs of the mirror field configured on each Connected item (if any)

You can find both information in the Elements Connect configuration screen (connected item IDs under the red rectangle, mirror fields under the yellow rectangle):


Elements Connect global admin at a glance



  • the ID of the target Jira Service Management project
  • the ID of the target Issue type
  • the ID of the target request type

You can find this information in the JSON representation of an issue, as returned by Jira REST API endpoint: https://<INSTANCE>.atlassian.net/rest/api/2/issue/<ISSUEKEY>: 



In our example, we want to set the value of the Connected item "Phone brand" on a "Get IT Help" request of the project "JP" - IDs we'll use are:

  • Project: 10009
  • Issue type: 10022
  • Request type: 23
  • Connected item: 10138
  • Mirror field: 10205

Execute the query

To create the issue, we'll use the "Create issue" endpoint of Jira REST API. The "Create customer request" endpoint of Jira Service Management REST API cannot be used to set Elements Connected items.
Beside the usual fields (like Summary, Description) we will also set the Issue Properties, which offer a way to store data against an issue. 

Here is the payload of the HTTP request:

JS
{
    "fields": {
        "issuetype": {
            "id": "10022"
        },
        "project": {
            "id": "10009"
        },
        "summary": "Created using the REST API",
        "customfield_10010": "23"
    },
    "properties": [
        {
            "key": "com.elements.connect.jira.cloud.issue.property",
            "value": {
                "schemaVersion":"1.0",
                "connectPropertyValues":[
                    {
                        "itemId":"10138",
                        "mirrorFieldId":"customfield_10206",
                        "values":["CAT"]
                    }
                ]
            }
        },
        {
            "key": "com.elements.connect.jira.cloud.items-values.exist",
            "value": "true"
        }
    ]
}

The important parts are:

  • connectPropertyValues: contains the value of each Elements Connected item. You can set multiple items but each item can only contain one value.
  • customfield_10000:it is the "Request type" custom field in our instance. This ID is certainly different on your instance.

What about readonly items?

It depends on their visibility. If they are visible on the request type, you must set their value in the payload.

We recommend to make them hidden on the portal. When doing so, Elements Connect will automatically set the value in the background when the issue is created.
In our example the readonly item "Phones of brand" is hidden on the portal. We find it more convenient to do it that way as it requires less work.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.