How to use fields parameter to include custom fields with spaces in their name

Johan picture Johan · Mar 27, 2015 · Viewed 7.7k times · Source

I've been building my REST query by using this reference: https://docs.atlassian.com/jira/REST/latest/#d2e2713

What I've managed so far: I get it to return JSON for me based on the JQL in the URL.

The problem I get: When I tell it what specific fields I want using the fields parameter, it seems to choke on the first custom field in the list (which also happens to have a space in its name).

The question: Does anyone know which of these two things is causing a problem, and how to solve it?

Specific detail:

Here's the URL I throw at Jira:

https://jira.mycorp.com/rest/api/latest/search?jql=project=PDEV+AND+type+in+(%22IA/E%22)+AND+createdDate+%3E=+2015-03-15&fields=assignee,status,resolution,%22DM%20Number%22,%22salesforce%20dd%20id%22

The response I get from Jira starts out like the below and continues for about a whole screen... but only returns the first three fields (assignee, status, resolution). I've figured out that the field names are case sensitive so I've tried different case schemes for the first custom field (the one you see in my example is how Jira renders the field name when you browse to the issue).

{
    "expand":"schema,names",
    "startAt":0,
    "maxResults":50,
    "total":17,
    "issues":    [
{       "expand":"editmeta,renderedFields,transitions,changelog,operations",
        "id":"769468",
        "self":"https://jira.mycorp.com/rest/api...

Maybe it will help to mention that my intent is to write a python script that will use REST to do issue searches like this so I can store it in a Python dict and do further processing on it. For now, I'm just telling Chrome to take me to the URL and reading the JSON it gets back.

Answer

Johan picture Johan · Mar 27, 2015

I found the last part of this puzzle here: https://answers.atlassian.com/questions/102822/how-can-i-find-the-id-of-a-custom-field-in-jira-5

Essentially, in the REST API you need to refer to custom fields by their ID, not their name - since the name is not necessarily unique in the Jira instance. To get a list of field names, execute http://localhost/rest/api/2/field and it will come back with a full list of custom fields including their IDs. The IDs take the form: customfield_16090.

So your fields parameter might take this form: fields='assignee,status,resolution,customfield_16090,customfield_16001'