Bug #19335
closedAdding media via the REST API does not correctly associate org/location
Description
When attempting to add Installation Media via the REST API, the location_ids and organization_ids are ignored and not set with the arrays returning empty:
curl -i -k -u admin:example -H "Content-Type: application/json" -X POST -d '{"name":"CentOS", "os_family":"Redhat", "path":"http://mirrors.centos.org/7/os/x86_64", "location_ids":[2], "organization_ids":[1]}' https://localhost/api/media
HTTP/1.1 201 Created
Date: Thu, 20 Apr 2017 17:05:54 GMT
Server: Apache/2.4.6 (CentOS)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Foreman_version: 1.13.4
Foreman_api_version: 2
Apipie-Checksum: 65f3b03cf7258e6366609106bbcf2e9a
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: 0dafaeca-32bf-4efe-beb1-2d5923cedc20
X-Runtime: 0.092155
X-Powered-By: Phusion Passenger 4.0.53
Set-Cookie: request_method=POST; path=/
Set-Cookie: _session_id=57a8066b95c5b6aa50241286a6696122; path=/; secure; HttpOnly
ETag: W/"391dfc43bf76631e346499f473b2cff7"
Status: 201 Created
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
{"path":"http://mirrors.centos.org/7/os/x86_64","os_family":"Redhat","created_at":"2017-04-20 17:05:54 UTC","updated_at":"2017-04-20 17:05:54 UTC","id":25,"name":"CentOS","operatingsystems":[],*"locations":[],"organizations":[]}*
I have verified the location and organization IDs are correct.
Updated by James Shewey over 7 years ago
Similarly:
[root@localhost ~]# curl -i -k -u admin:218B0DwX5x9rkPKQNlHp -H "Content-Type: application/json" -X PUT -d '{"location_ids":[2]}' https://localhost/api/media/25
HTTP/1.1 200 OK
Date: Thu, 20 Apr 2017 17:21:44 GMT
Server: Apache/2.4.6 (CentOS)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Foreman_version: 1.13.4
Foreman_api_version: 2
Apipie-Checksum: 65f3b03cf7258e6366609106bbcf2e9a
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: a353823d-3b35-4968-8a63-266bea8fffa2
X-Runtime: 0.068420
X-Powered-By: Phusion Passenger 4.0.53
Set-Cookie: request_method=PUT; path=/
Set-Cookie: _session_id=5a582e06ca1765b7f426fed537af5f7c; path=/; secure; HttpOnly
ETag: W/"c105aa9f477eea37076fec2e6f1f2702"
Status: 200 OK
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
{"path":"http://mirrors.centos.org/7/os/x86_64","os_family":"Redhat","created_at":"2017-04-20 17:05:54 UTC","updated_at":"2017-04-20 17:19:41 UTC","id":25,"name":"CentOSTest","operatingsystems":[],"locations":[],"organizations":[]}
[root@localhost ~]# curl -i -k -u admin:218B0DwX5x9rkPKQNlHp -H "Content-Type: application/json" -X PUT -d '{"organization_ids":[2]}' https://localhost/api/media/25
HTTP/1.1 200 OK
Date: Thu, 20 Apr 2017 17:22:31 GMT
Server: Apache/2.4.6 (CentOS)
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Foreman_version: 1.13.4
Foreman_api_version: 2
Apipie-Checksum: 65f3b03cf7258e6366609106bbcf2e9a
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: a2362dee-46f5-4e2b-8e12-5b59a05c435d
X-Runtime: 0.067945
X-Powered-By: Phusion Passenger 4.0.53
Set-Cookie: request_method=PUT; path=/
Set-Cookie: _session_id=2f4e94e9c0b514d6a681d819dcb3ec2a; path=/; secure; HttpOnly
ETag: W/"c105aa9f477eea37076fec2e6f1f2702"
Status: 200 OK
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
{"path":"http://mirrors.centos.org/7/os/x86_64","os_family":"Redhat","created_at":"2017-04-20 17:05:54 UTC","updated_at":"2017-04-20 17:19:41 UTC","id":25,"name":"CentOSTest","operatingsystems":[],"locations":[],"organizations":[]}
Updated by James Shewey over 7 years ago
This is a documentation/API bug. Two bugs really. First, the API should throw a proper error. Secondly, the documentation indicates the correct syntax is:
medium[operatingsystem_ids]
optional , nil allowed
Validations: Must be an array of any type
However,
The syntax is:
curl -i -k -u admin:example -H "Content-Type: application/json" -X PUT -d '{"locations": [{"id":1}]}' https://localhost/api/media/30/
So, in summary:
1) API does not properly throw error
2) Documentation indicates wrong parameter name ("example_ids" should be "examples")
3) Documentation states this takes an array of any type; it does not. It takes an array of hashes
Updated by Justin Sherrill over 7 years ago
- Project changed from Katello to Foreman
This isn't katello related, so moving to foreman
Updated by Dominic Cleal over 7 years ago
- Is duplicate of Bug #6991: API v2 - support unwrapped POST/PUT parameters even though it's not documented added
Updated by Dominic Cleal over 7 years ago
- Category set to API
- Status changed from New to Duplicate
- Translation missing: en.field_release deleted (
226)