There are two ways to add/remove associations in API v2 for PUT and POST.
The question is which one (or both) are we going to document and support going forward?
- pass data attribute *_ids=[array,of,ids] in POST/PUT. This requires that the data attributes are WRAPPED within an object node.
- pass child node in PUT/POST data hash similar to what is received in GET. This requires that the data attributes are NOT WRAPPED within an object node.
Example: PUT api/v2/operatingsystems/24
Ex #1) WRAPPED in object node and use *_ids - this works
{
"operatingsystem": {
"name": "CentOs",
"config_template_ids": [36, 12, 40, 4, 3, 1]
}
}
Ex #2) NOT WRAPPED in object node and use child node - this works
PUT api/v2/operatingsystems/24
{
"name": "CentOs",
"config_templates": [
{
"id": 36,
"name": "CentOS-enabled-post"
},
{
"id": 12,
"name": "Grubby Default"
},
{
"id": 40,
"name": "Katello Kickstart Default",
},
{
"id": 4,
"name": "Kickstart Default"
},
{
"id": 3,
"name": "Kickstart default gPXE"
},
{
"id": 1,
"name": "Kickstart default PXElinux"
}
]
}
The examples will NOT work! (even though users may assume that they would)
Ex #3) NOT WRAPPING in object node using *_ids when it NEEDS TO BE. This does NOT give an error, but does NOT update config_template_ids.
params['config_template_ids'] is IGNORED in @operatingsystem.update_attributes(params[:operatingsystem])
{
"name": "CentOs",
"config_template_ids": [36, 12, 40, 4, 3, 1]
}
Ex #4) WRAPPING child node within object node when it SHOULD NOT BE. This gives an ERROR. { "message": "ConfigTemplate(#98749620) expected, got ActiveSupport::HashWithIndifferentAccess(#18888980)"}
{
"operatingsystem": {
"name": "CentOs",
"config_templates": [
{
"id": 36,
"name": "CentOS-enabled-post"
},
{
"id": 12,
"name": "Grubby Default"
},
{
"id": 40,
"name": "Katello Kickstart Default",
},
{
"id": 4,
"name": "Kickstart Default"
},
{
"id": 3,
"name": "Kickstart default gPXE"
},
{
"id": 1,
"name": "Kickstart default PXElinux"
}
]
}
}
Regards,
Joseph