January 31, 2022

Link Jira issues to a customer with JQL using the API

Timo van der Kamp

Software developer

Share this article

It is now possible to link Jira issues to a customer in Atlas CRM with our new API. In this blog I will guide you through the steps that you will need to take to do this with JQL.

No linked issues yet

I want to link some Jira issues to my customer Avisi, more specifically all issues from the Jira project “PFA”. Doing this one by one can be really time consuming and therefore I would like to do this with the API.

The following Atlas CRM API endpoint can be used to link Jira issues to a customer.

-- CODE language-js line-numbers --POST /api/1.0/workspace/CRM/entities/{entity-id}/issues {"issue-ids": []}

Retrieve the ID for Avisi

First of we need to fill the {entity-id} path-parameter with the ID of Avisi. There are several ways to obtain the ID of a company, contact or sale in Atlas CRM:

1. Retrieve it from the app location

ID in app location

2. Retrieve it from the API with a filter

-- CODE language-js line-numbers --GET /api/1.0/workspace/CRM/entities?type=company&fields.company-name=Avisi

-- CODE language-js line-numbers --{"items" [{"id" "vAXEux8DEqls0Dk99pqj", "type" "company", "fields" {"company-website" "www.avisi.nl", "company-name" "Avisi"}, "_links" {"self" {"href" "https://atlascrm.avisi-apps.com/api/1.0/workspace/CRM/entities/vAXEux8DEqls0Dk99pqj"}, "app" {"href" "https://atlascrm.avisi-apps.com/test-timo/workspace/CRM/company/vAXEux8DEqls0Dk99pqj/information"}}}], "total" 1, "_links" {"self" {"href" "https://atlascrm.avisi-apps.com/api/1.0/workspace/CRM/entities?fields.company-name=Avisi&type=company"}}}

Fetch Jira issues with JQL

Now that we have the ID for Avisi, we only need to pass a list of issue-ids to the Atlas CRM API to make the links. But how do we get these issue-ids?

We can use the Jira Cloud Rest API to fetch issues with JQL. First, I have made the JQL query in Jira to verify the result.

Query all Jira issues from project “PFA”.

Everything looks good to me, so I am going to use this JQL query in the Jira API to search for issues. You can use this endpoint to search for issues with JQL. More information.

-- CODE language-js line-numbers --GET /rest/api/3/search?jql=project=PFA ORDER BY created DESC

-- CODE language-js line-numbers --{"expand": "schema,names", "startAt": 0, "maxResults": 50, "total": 10, "issues": [{"expand": "customfield_10020.requestTypePractice,operations,versionedRepresentations,editmeta,changelog,renderedFields",             "id": "10145",             "self": "https://test-timo.atlassian.net/rest/api/3/issue/10145",             "key": "PFA-10",             "fields": {}},             ...

In the result from the Jira API you can find the ID’s of the Jira issues that you need.

Use the ID’s in the Atlas CRM API

Now that we have got the entity-id path-parameter and the issue-ids, we can make the API call to actually link these together.

-- CODE language-js line-numbers --POST /api/1.0/workspace/CRM/entities/vAXEux8DEqls0Dk99pqj/issues {"issue-ids": ["10145", "10144", "10143" ...]}

Issues are linked to Avisi

Try the Atlas CRM API out yourself and check our API documentation for all integration possibilities. If you need help configuring your integration, please reach out to our support desk.

Share this article