Is there a way in which I could get the epic for an issue ?
The api returns a lot of information about an issue, but the epic is not included.
I'm using the JIRA REST API (https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs).
Is there a way in which I could get the epic for an issue ?
The api returns a lot of information about an issue, but the epic is not included.
I'm using the JIRA REST API (https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs).
I wanted to extract the epic name for an issue
and this stumped me for a few days.
The key was to realise that an epic
is just a parent issue, and the epic name is the summary
field of the parent issue
.
So:
Step 1
Find the custom field of where the epic is stored by using the editmeta
query:
https://[your-jira-hostname]/jira/rest/api/2/issue/[issue-number]/editmeta
This will yield something like below which reveals the custom field Id we need
{
"fields": {
<SNIP>
"customfield_12360": {
"required": false,
"schema": {
"type": "any",
"custom": "com.pyxis.greenhopper.jira:gh-epic-link",
"customId": 12360
},
"name": "Epic Link",
"operations": [
"set"
]
}
<SNIP>
}
}
Step 2
Query your issue, pulling out the custom field value
https://[your-jira-hostname]/jira/rest/api/2/issue/[issue-number]?fields=customfield_12360,summary
if our issue is JIRA-34
say, this will yield something like
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
"id": "39080",
"key": "JIRA-34",
"fields": {
"summary": "Write heavily upvoted answers for stack overflow",
"customfield_12360": "JIRA-33"
}
}
Step 3
Now we know the issue number of our epic is JIRA-33
, so now query the epic...
https://[your-jira-hostname]/jira/rest/api/2/issue/JIRA-33?fields=summary
{
"expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
"id": "39080",
"key": "JIRA-33",
"fields": {
"summary": "Improve StackOverflow reptuation"
}
}
The name of the epic for JIRA-34
is "Improve StackOverflow reptuation"
Done.
/rest/api/3/field/search?type=custom&query=Epic%20Link
. This is useful if you need to pull out epic links from a call to the issue search API for example. API docs are here: developer.atlassian.com/cloud/jira/platform/rest/v3/… –
Parshall To get the epic key for an issue:
Send a request to: /issue/ISSUE-NUMBER
And look at the response body:
{
...,
fields: {
...,
customfield_11300: ... <- here, the epic should be listed. The number can be different
}
}
customfield_10101
, for example. So this is not a reliable way of retrieving the epic link. –
Bortz @fiat have the very clear steps to find the custom field and epic mapping. In my scenario, the whole jira instance is using the same custom field as epic. So I won't need to repeat those steps to map for each project. Hope this could help.
According to https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-fields/ , you can make a API call to /rest/api/3/field
, then you can get data like this:
[
{
"id": "customfield_10014",
"key": "customfield_10014",
"name": "Epic Link",
"untranslatedName": "Epic Link",
"custom": true,
"orderable": true,
"navigable": true,
"searchable": true,
"clauseNames": [
"cf[10014]",
"Epic Link"
],
"schema": {
"type": "any",
"custom": "com.pyxis.greenhopper.jira:gh-epic-link",
"customId": 10014
}
},
]
Then look back to your issue json data:
issue:
fields:
....
customfield_10014: OT-5
....
The OT-5
is the Epic's key.
© 2022 - 2024 — McMap. All rights reserved.