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 #1

Updated by Jean-Philippe Lang over 8 years ago

  • Target version set to 3.2.3
Actions #2

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.

Actions #3

Updated by Maxim Krušina over 7 years ago

  • Related to Feature #26017: Get also labels for key/value custom fields by API added
Actions

Also available in: Atom PDF