Incorrect DB record format when creating groups via REST API

I would like to share with you the problem we were facing when automating creation of groups via REST API. (ManageIQ hammer-4.20190329011451_d08635f )
The create request is done by shell script using curl command like this:

curl -s -k -H “Content-Type: application/json” -X POST --data “{“description” : “{NEW_GROUP_NAME}\", \"role\" : { \"id\" : \"{roleId}” }, “tenant” : { “href” : “{MIQ_BASE_URL}tenants/{tenantId}” }, “filters” : { “managed” : [ “/managed/visibility/ap_cld_tribe1_sqd1”, “/managed/visibility/all_groups”]}}” -u “{MIQ_USER}:{MIQ_PASSWORD}” “${MIQ_BASE_URL}groups”

The groups seemed to be created properly but in the ManageIQ console, you are unable to get their details when selecting one.

Checking DB, it shows that YAML is incorrectly formatted compared to the original groups created in the MIQ console:
new group:

original group:

In order to use the newly created groups properly, it is necessary to fix the DB afterwards by running DB update like this:

update entitlements set filters = REGEXP_REPLACE(filters,'managed:\n[^"]’,‘managed:’ || chr(10) || '- - ',‘g’) where filters ~ ‘managed:\n-’ and filters !~ ‘managed:\n- -’;*

update entitlements set filters = REGEXP_REPLACE(filters,’"\n-’,’"’ || chr(10)|| ’ - ',‘g’) where filters ~ ‘"\n- "’;

Anyone having same experience? Is there any other way to avoid this issue?

Thanks a lot!

It looks like what you’re getting is correct based on the request you’re posting to the API.

The quick answer is that you need an extra array in you’re json. Right now your request contains {"managed":["/managed/visibility/ap_cld_tribe1_sqd1","/managed/visibility/all_tribes"]} but what you want is: {"managed":[["/managed/visibility/ap_cld_tribe1_sqd1","/managed/visibility/all_tribes"]]}

You can see this in the following example:

10:09:49:~$ cat new.yaml 
- "/managed/visibility/ap_cld_tribe1_sqd1"
- "/managed/visibility/all_tribes"
10:09:50:~$ cat orig.yaml 
- - "/managed/visibility/ap_cld_tribe1_sqd1"
  - "/managed/visibility/all_tribes"

10:09:52:~$ irb
irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> require 'json'
=> true

irb(main):004:0> new = YAML.load_file("new.yaml")
=> {"managed"=>["/managed/visibility/ap_cld_tribe1_sqd1", "/managed/visibility/all_tribes"]}
irb(main):006:0> puts new.to_json
=> nil

irb(main):007:0> orig = YAML.load_file("orig.yaml")
=> {"managed"=>[["/managed/visibility/ap_cld_tribe1_sqd1", "/managed/visibility/all_tribes"]]}
irb(main):008:0> puts orig.to_json
=> nil

Hope this helps.