How do I get all custom fields of an issue using rest api?

mohan_rao June 11, 2013

Previously, we are gettng all custom fields for specified issue from "RemoteIssue" object as RemoteIssue.customFieldValues. How to get same data using REST API for specific issue?

Thanks

Mohan

4 answers

6 votes
Richard Ranft February 2, 2015

Wouldn't it be better to make custom fields a collection in the API like this:

{
  "customfields": [
    "customfield": {
      "required": false,
      "schema": {
        "type": "number",
        "custom": "com.atlassian.jira.plugin.system.customfieldtypes:float",
        "customId": 10112
      },
      "name": "count",
      "operations": [
        "set"
      ]
    },
    "customfield": {
      "required": false,
      "schema": {
        "type": "string",
        "custom": "com.atlassian.jira.plugin.system.customfieldtypes:float",
        "customId": 10100
      },
      "name": "count",
      "operations": [
        "set"
      ]
    }
  ]
}

That way there wouldn't be this giant hassle of finding "customfield_" in the text, trying to parse out the custom field, etc.  It just comes back as a collection of custom field objects that can be readily converted using standard JSON.  Since there are only a few "shapes" of custom fields on the client side I could make an aggregate object that could accept any of the types and the missing fields just get ignored.

Or am I completely missing something?

Sascha Schwegelbauer July 14, 2015

You're absolutely right. Don't know what ugly serializer Atlassian uses, but this mixture of named fields and custom fields makes it really bad to deserialize.

Isaac Abramowitz May 6, 2019

I'm having the same issue. It needs to be more dynamic for me. I need to be able to access a custom field by the user inputting the field name. This will only work in an array for me at the moment since I can store an array of objects, but I can't store an object linked to a field who's name is not yet known.

 

Does anyone know if there has been a fix to this problem or alternate solutions since 2015?

Like Jonathan Bratt likes this
4 votes
Jens Knipper January 22, 2014

Try using GET on

api/2/issue/{issueIdOrKey}/editmeta

Your output should be similar to this. It contains ALL fields.

{
  "fields": {
    "customfield_10112": {
      "required": false,
      "schema": {
        "type": "number",
        "custom": "com.atlassian.jira.plugin.system.customfieldtypes:float",
        "customId": 10112
      },
      "name": "count",
      "operations": [
        "set"
      ]
    },
    "summary": {
      "required": true,
      "schema": {
        "type": "string",
        "system": "summary"
      },
      "name": "sum",
      "operations": [
        "set"
      ]
    }
}

If you want to get the fileds values try Aleksander's code

3 votes
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 11, 2013

https://docs.atlassian.com/jira/REST/latest/

Just use the /rest/api/2/issue/{issueIdOrKey} and there will be fields field inside response. All custom fields are there with customfield_{id} name.

For example try: GET https://jira.atlassian.com/rest/api/latest/issue/JRA-31629

If that's not what you need, then I need more info about what you need.

mohan_rao June 11, 2013

Yes Aleksander, i tried similar way. Here the problem is, all customfield_{id} are not coming in same structure. See the below data structure what i got,

"fields": {
"customfield_10050": {
				"self": "link to field",
				"value": "Severe",
				"id": "10050"
			},
"customfield_10387": "7523",
"customfield_10388": null
}

So, not able to deserialize custom field JSON to .Net(C#) objects. Any idea how can i proceed?

One more problem here is, all customfield_{id} are not coming at one place(as collection).

Like # people like this
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 11, 2013

You probably want to use expand=schema (and names if you also need the field name). When you run request with that option you'll get schema in reply, which says what is the type for field. So you will be able to parse field value according to its type.

For example, schema entry for customfield_10610:

"customfield_10610":
{
     "type": "number",
     "custom": "com.atlassian.jira.plugin.system.customfieldtypes:float",
    "customId": 10610
},

Andy Kuan December 30, 2015

I have check if not null and blank, but some fileds got object reference not set exception error if (!string.IsNullOrEmpty(issueResp.Issues[i].Fields.customfield_10709.value)) buildrequest.DbName = issueResp.Issues[i].Fields.customfield_10709.value;

Like justin likes this
2 votes
uuuu April 9, 2014

Different projects in JIRA might have different customfields mapped to it. The get below should provide all customfields for project JRA.

https://jira.atlassian.com/rest/api/latest/issue/createmeta?projectKeys=JRA&issuetypeName=Bug&expand=projects.issuetypes.fields

I think the only way to get customfields and issuesTypes are based on query to specific projects.

awurster
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 15, 2015

this is the most accurate response actually. according to this example in the doc specs, you need to specify the "expand" parameter. interestingly enough, you can leave off the projectKeys and issuetypeName filters and just dump back the entire lot. rest/api/latest/issue/createmeta?expand=projects.issuetypes.fields https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-discovering-meta-data-for-creating-issues

Like Mathias Merbold likes this
Dirk March 16, 2018

Take care: " Fields not in the screen will not be in the createmeta. "

vengala rao March 28, 2018

Is it possible to further filter and get only certain custom fields based on If those fields are required or not. Or do I have to add that Logic from where I consume JIRA2 API? 

The problem for me is when I use the above query I'll be getting 6000 lines of JSON response.. but If I can filter to get only customfield_{id}' s which are required there will be only ~100 lines of response. Please let me know If it's doable or not otherwise I'll filter in the consuming project after I got response back. TIA

Suggest an answer

Log in or Sign up to answer