Jira API v3 - Include Sprint in Get Issue Search

How do I include the Sprint details when I get issues using /rest/api/3/search ?

I am successfully retrieving the list of all issues (for a given project) with:

request.get({
      url: 'https://api.atlassian.com/ex/jira/'+ req.user.jiraCloudid +'/rest/api/3/search',
      headers: { 'Authorization' : 'Bearer ' + res.locals.jiraToken},
      'qs': {
        'jql': 'project='+req.session.projectId,
        'fields': 'summary,description,assignee,labels,priority,issuetype,status,sprint',
      }

I have tried 'fields' : '*all' which does return additional fields, but not information about the Sprint that each issue is in.

Sprint is a custom field, so you first need to figure out its ID using the GET /rest/api/2/field API. You should find the following entry there:

  {
    "id": "customfield_X",
    "key": "customfield_X",
    "name": "Sprint",
    "custom": true,
    "orderable": true,
    "navigable": true,
    "searchable": true,
    "clauseNames": [
      "cf[X]",
      "Sprint"
    ],
    "schema": {
      "type": "array",
      "items": "string",
      "custom": "com.pyxis.greenhopper.jira:gh-sprint",
      "customId": X
    }
  }

(where X is a number different on every instance).

Then use that custom field key in the “fields” list:

'fields': 'customfield_X,summary,description,assignee,labels,priority,issuetype,status'
1 Like

Thanks for your solution.

We’re using api v3. But it seems /rest/api/3/field is same as /rest/api/2/field so the solution will still work… unless you know something we need to watch out for?

Also, since we’re using /search endpoint to get a list of issues it seems we have two options

i) use regex on customfield_x
ii) include expand : versionedRespresentations and reference the JSON value inside customfield_x

Does that sound right? Do you recommend one over the other?

Thanks

Using versionedRepresentations is the recomended way, since the string representation is deprecated and should not be relied on.

I would also recommend using the version 2 of the API, since version 3 is in beta. But in practice they are the same, the only difference being version 3 uses ADF, and version 2 - plain text for rich-text fields.

1 Like