Project

General

Profile

Actions

Defect #22745

closed

Rest API for Custom Fields does not return keys for key/value types

Added by Stephen Stuart over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Category:
REST API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

When using the REST API to retrieve the list of custom_fields by calling http://localhost:3000/custom_fields.json , if there is a Key/Value list type custom fields only the value comes back, as in the example below:

"id": 5,
"name": "Lifecycle Status",
"customized_type": "version",
"field_format": "enumeration",
"regexp": "",
"visible": true,
"possible_values": [
  {
    "value": "2",
  },
  {
    "value": "3",
  },
  {
    "value": "4",
  }
]

to replace this block:
It would be much more useful to get the name back as well, like:
"id": 5,
"name": "Lifecycle Status",
"customized_type": "version",
"field_format": "enumeration",
"regexp": "",
"visible": true,
"possible_values": [
  {
    "value": "2",
    "label": "Planned" 
  },
  {
    "value": "3",
    "label": "In Progress" 
  },
  {
    "value": "4",
    "label": "Complete" 
  }
]

I did this in a plugin by overriding app/views/custom_fields/index.api.rsb and adding and if block checking for EnumerationFormat.

      values = field.possible_values_options
      if values.present?
        api.array :possible_values do
          values.each do |label, value|
            api.possible_value do
              api.value value || label
              if field.format.class.name.demodulize == 'EnumerationFormat'
                  api.label label
              end
            end
          end
        end
      end

I was going to just put the 'api.label label' line in without the if statement but it also takes effect for list types where label and value appear to be the same. There is almost certainly a better way to do this.


Related issues

Related to Redmine - Feature #26017: Get also labels for key/value custom fields by APINew

Actions
Actions

Also available in: Atom PDF