How to get list of issuekey in specific issuelink on an issue

Hi,
We are trying to list the issues from specific issuelink:
for exemple we want to list all the issuekeys for issuelink.type.name = “Contient”
and get all the outwards issues on it.

def issueKey = ‘SSDBG-940’
def result = get(‘/rest/api/2/issue/’ + issueKey)
.header(‘Content-Type’, ‘application/json’)
.asObject(Map)
return result.body.fields.issuelinks

we would like to have in te result : {SSDBG-941,SSDBG-942}
Could you help me find the syntax please to add condition to only have all the issuekey from issuelink “Contient” ?

the return of the result.body.fields.issuelinks is :
[
{
“id”: “18509”,
“type”: {
“id”: “10014”,
“name”: “Contient”,
“inward”: “appartient à”,
“outward”: “contient”,
},
“outwardIssue”: {
“id”: “24965”,
“key”: “SSDBG-941”,
“fields”: {
“summary”: “test date - RUN1”,
“status”: {
“description”: “(Migrated on 7 Mar 2023 13:10 UTC)”,
“name”: “Confirmee”,
“id”: “10027”,
“statusCategory”: {
“id”: 2,
“key”: “new”,
“colorName”: “blue-gray”,
“name”: “To Do”
}
},
“issuetype”: {
“id”: “10031”,
“description”: " (Migrated on 17 Oct 2022 15:20 UTC)“,
“name”: “Mission BA”,
“subtask”: false,
“avatarId”: 10313,
“hierarchyLevel”: 0
}
}
}
},
{
“id”: “18510”,
“type”: {
“id”: “10014”,
“name”: “Contient”,
“inward”: “appartient à”,
“outward”: “contient”,
},
“outwardIssue”: {
“id”: “24966”,
“key”: “SSDBG-942”,
“fields”: {
“summary”: “test date - RUN2”,
“status”: {
“description”: “(Migrated on 7 Mar 2023 13:10 UTC)”,
“name”: “Confirmee”,
“id”: “10027”,
“statusCategory”: {
“id”: 2,
“key”: “new”,
“colorName”: “blue-gray”,
“name”: “To Do”
}
},
“issuetype”: {
“id”: “10031”,
“description”: " (Migrated on 17 Oct 2022 15:20 UTC)”,
“name”: “Mission BA”,
“subtask”: false,
“avatarId”: 10313,
“hierarchyLevel”: 0
}
}
}
},
{
“id”: “18511”,
“type”: {
“id”: “10013”,
“name”: “Lié à”,
“inward”: “même groupe que”,
“outward”: “même groupe que”,
},
“outwardIssue”: {
“id”: “24956”,
“key”: “SSDBG-937”,
“fields”: {
“summary”: “test indep”,
“status”: {
“description”: “(Migrated on 7 Nov 2022 11:22 UTC)”,
“name”: “Active”,
“id”: “10023”,
“statusCategory”: {
“id”: 2,
“key”: “new”,
“colorName”: “blue-gray”,
“name”: “To Do”
}
},
“issuetype”: {
“id”: “10039”,
“description”: " (Migrated on 17 Oct 2022 15:20 UTC)",
“name”: “Travaux C1 - BA”,
“subtask”: false,
“avatarId”: 10307,
“hierarchyLevel”: 0
}
}
}
},
{
“id”: “18508”,
“type”: {
“id”: “10019”,
“name”: “Réserve”,
“inward”: “est réservé(e) par”,
“outward”: “réserve”,
},
“inwardIssue”: {
“id”: “24963”,
“key”: “SSDBG-939”,
“fields”: {
“summary”: "test date “,
“status”: {
“description”: “(Migrated on 10 Mar 2023 13:51 UTC)”,
“name”: “Archivee”,
“id”: “10030”,
“statusCategory”: {
“id”: 3,
“key”: “done”,
“colorName”: “green”,
“name”: “Done”
}
},
“issuetype”: {
“id”: “10013”,
“description”: " (Migrated on 17 Oct 2022 15:20 UTC)”,
“name”: “Reservation Phoenix BA”,
“subtask”: false,
“avatarId”: 10323,
“hierarchyLevel”: 0
}
}
}
}
]

Welcome to the Atlassian Developer Community, @MiriCHENEFR!

For this specific use case, you might want to use the Search for issues using JQL, this way you can search for issues linked to the issue (SSDBG-940) with an issue link type of “Contient”.

The request would look something like this:

GET {{baseUrl}}/rest/api/2/search?jql= issueLink = SSDBG-940 and issueLinkType = "Contient" &fields=key

This will result in an issues array that is linked to the desired issue of the indicated issue link type. You just need to parse the response body to get the issue keys.

Do try it out and let us know how it goes.

Cheers,
Ian

Hi

To get a list of issue keys for outward issues with issuelink type “Contient” for a given issue, you can modify the existing code. This code filters the issue links by type name “Contient” and then retrieves the outward issues for those filtered issue links. Finally, the code collects the issue keys for each outward issue and returns them as a list. This is how we guide at Triotech Systems

Use this

def issueKey = 'SSDBG-940'
def result = get('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.asObject(Map)

def issueLinks = result.body.fields.issuelinks.findAll{it.type.name == 'Contient'}.outwardIssue
def issueKeys = issueLinks.collect{it.key}

return issueKeys

1 Like