Foreman V2 Subnets API - Update of parameters does not work


I get an error whenever i try to update parameter data for subnets via Foreman Rest API.

Expected outcome:
Successful update of subnets parameter data

Foreman and Proxy versions:

Foreman and Proxy plugin versions:

Other relevant data:
Here you find some log lines from our api calls

2024-02-21 11:54:15,279 [DEBUG] Call endpoint https : // foreman . example . com/api/subnets/152/parameters/61963 with method: PUT
*Input parameters*
2024-02-21 11:54:15,280 [DEBUG] With INPUT data: {'id': '61963', 'parameter': {'name': 'environments', 'parameter_type': 'array', 'value': ['TEST']}}
*Formen tells me that all was OK*
2024-02-21 11:54:15,992 [INFO] Response status code when calling URL "https :  // foreman .example. com/api/subnets/152/parameters/61963"**: 200**
*Response data tells me that data was not changed.*
2024-02-21 11:54:15,992 [INFO] Response data: {"priority":40,"created_at":"2022-09-21 08:49:09 UTC","updated_at":"2022-09-21 08:49:09 UTC","id":61963,"name":"environments","parameter_type":"array","value":["DEV"]}

Parameter exists in foreman

Input Json

    "id": "61963",
    "parameter": {
        "name": "environments",
        "parameter_type": "array",
        "value": [

In production.log i can find this entry:

2024-02-21T13:39:52 [I|app|37a7c11d] Processing by Api::V2::ParametersController#update as JSON
2024-02-21T13:39:52 [I|app|37a7c11d]   Parameters: {"id"=>"61963", "parameter"=>{"name"=>"environments", "parameter_type"=>"array", "value"=>"[FILTERED]"}, "apiv"=>"v2", "subnet_id"=>"152"}
2024-02-21T13:39:52 [I|app|37a7c11d] Authorized user osstool(OSS Tool)
2024-02-21T13:39:52 [I|app|37a7c11d]   Rendering api/v2/parameters/update.json.rabl
2024-02-21T13:39:52 [I|app|37a7c11d]   Rendered api/v2/parameters/update.json.rabl (Duration: 14.0ms | Allocations: 7359)
2024-02-21T13:39:52 [I|app|37a7c11d] Completed 200 OK in 190ms (Views: 12.7ms | ActiveRecord: 56.6ms | Allocations: 36480)

I have implemented it based on doc:

I have also tried to set the user to admin, but no luck.

Does someone have any idea on this?

Thanks & BR

I am not 100% sure on this, but from a quick look at the docs and a glance at the code, the “value” field needs to be a string, no matter what the parameter type is. The API parses the value through json.dumps to actually get the data as json. So try wrapping the array into a string.

Many thanks for that. This solution works (even when i would not had expected that :sweat_smile:)

1 Like