Defect #22745
closedRest API for Custom Fields does not return keys for key/value types
0%
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
Updated by Jean-Philippe Lang over 8 years ago
- Status changed from New to Closed
- Assignee set to Jean-Philippe Lang
- Target version changed from 3.2.3 to 3.3.0
- Resolution set to Fixed
Stephen Stuart wrote:
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.
I've added the label for all custom fields that have possible values
It's better to have the same behaviour no matter the custom field type, even if value and label are the same.
Thanks for pointing this out.
Updated by Maxim Krušina over 7 years ago
- Related to Feature #26017: Get also labels for key/value custom fields by API added