Share this post on:

Recently I have been working on building application that enables creating JIRA issues with the use its API. I must say, it is pretty much well documented, but despite that, I was having some problems with getting specific information needed for me.

As mention in the title, my main issue was to get the available Sprints for given project. Sprint data is stored in so called ‘custom field’. Difference between this fields and ‘normal’ field is naming convention and the way we can retrieve their values. By normal fields I am talking e.g. about labels , project, duedate and many more – those names are used exactly for their ids.

Custom fields are always a combination of ‘customfield’ string and ID number, e.g. customfield_10104 – in my case exactly this field was used for Sprint field.

I had a task for providing the user a dropdown with the list of sprints – that was all. Additionally I had also in the back of my head my next task, that was retrieving possible values for two other custom fields.

I thought that after figuring out the way of getting sprints, I will be able to use this same solution for my next task – boy, was I surprised.

I was reading the documentation, and found out some nice features like e.g. getting list of available labels – those are global for all project.

/rest/api/3/jql/autocompletedata/suggestions?fieldName=labels&fieldValue=

I simply thought that I will be able to get sprints with this same REST, by only changing the ‘labels’ to ‘customfield_10104’

Unfortunately I got empty result list, as a result of my search. I thought, ok to be honest it was not the way to go, since this REST do not use the projectId, that I really need it.

I found anothere way to retrieve data for given field – it was this approach:

/rest/api/3/project/MY_PROJECT_KEY/version

Example above is used for getting list of versions for project with key MY_PROJECT_KEY (you can use project ID as well in this REST, it will work). When I changed ‘version’ to my custom field id and I got response:

<status>
<status-code>404</status-code>
<message>null for uri: .../rest/api/3/project/MY_PROJECT_KEY/customfield_10104</message>
</status>

Ok, so not this way as well. I decided to search for something that was exactly specified for getting information for custom fields, and I found out that there is such a way. Section Get custom fields context, seems like a solution for me. So I gave it a try, and….. again 404 error page.

I also found out the url for getting all custom fields…

/rest/api/3/customFields 

… but I got response that I need admin rights to access this URL.

I found out that there is well known way for getting available options for custom fields with the use of ‘createmeta’ REST, and finally my call looked like this:

/rest/api/3/issue/createmeta?projectKeys=MY_PROJECT_KEY&issuetypeNames=Task&expand=projects.issuetypes.fields

I got big JOSN response, I searched for my field, and there was not availableOptions key in it!

            "customfield_10104": {
              "required": false,
              "schema": {
                "type": "array",
                "items": "string",
                "custom": "com.pyxis.greenhopper.jira:gh-sprint",
                "customId": 10104
              },
              "name": "Sprint",
              "fieldId": "customfield_10104",
              "hasDefaultValue": false,
              "operations": [
                "set"
              ]
            },

Just to be sure what is going on, I checked other custom fields, especially the ones I will be using in my next task. One of them was ‘customfield_10504’. I found out that there were availableOptions for those custom fields:

            "customfield_10504": {
              "required": false,
              "schema": {
                "type": "array",
                "items": "option",
                "custom": "com.atlassian.jira.plugin.system.customfieldtypes:multiselect",
                "customId": 10504
              },
              "name": "Names",
              "fieldId": "customfield_10504",
              "hasDefaultValue": false,
              "operations": [
                "add",
                "set",
                "remove"
              ],
              "allowedValues": [
                {
                  "self": ".../rest/api/2/customFieldOption/10709",
                  "value": "John",
                  "id": "10709",
                  "disabled": false
                },
                {
                  "self": ".../rest/api/2/customFieldOption/10710",
                  "value": "Mike",
                  "id": "10710",
                  "disabled": false
                },
                {
                  "self": ".../rest/api/2/customFieldOption/10717",
                  "value": "Larry",
                  "id": "10717",
                  "disabled": false
                }
              ]
            },

So I had one answer – getting available options for my two other custom fields. But what is wrong with the Spring custom field. Finally after looking in the internet I found I that this field is treated a bit differently. It was added by so called greenhopper plugin, and to retrieve information about available Sprints different REST API must be used. The one to go with is:

/rest/greenhopper/1.0/sprint/picker

After using this I was finally able to get all Sprints. Additionally I passed project parameter and my finally URL was:

/rest/greenhopper/1.0/sprint/picker?project=MY_PROJECT_KEY

And response was:

{
  "suggestions": [
    {
      "name": "Test Sprint 3",
      "id": 169,
      "stateKey": "FUTURE",
      "boardName": "Test Board",
      "date": ""
    }
  ],
  "allMatches": [
    {
      "name": "Test Sprint 2",
      "id": 168,
      "stateKey": "ACTIVE",
      "boardName": "Test Board",
      "date": "2021-09-27T09:35:0Z"
    },
    {
      "name": "Test Sprint 4",
      "id": 170,
      "stateKey": "FUTURE",
      "boardName": "Test Board",
      "date": ""
    }
  ]
}

To sum up, if you do not have admin rights, and you want to get available options for custom fields use this:

 /rest/api/3/issue/createmeta?projectKeys=MY_PROJECT_KEY&issuetypeNames=Task&expand=projects.issuetypes.fields 

To get available Sprints use this:

/rest/greenhopper/1.0/sprint/picker?project=MY_PROJECT_KEY

Hopefully someone will find this article useful. If you find out another way for getting Sprints, with the use of project Id/Key please write some info in comment section.