JIRA API: Get epic for issue
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
}
}
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.