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

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

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?

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.

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

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.

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).

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
},

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;

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.

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,847 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot