go-netbox icon indicating copy to clipboard operation
go-netbox copied to clipboard

Unable to write json string to device's local_context_data

Open stefanhipfel opened this issue 4 years ago • 0 comments
trafficstars

Hi,

I currently want to write some struct data to a device's local_context_data. However since this parameter needs to be a *string (local_context_data), I need to json.Marshal my go struct to a string. When using the go openapi runtime as the client.Transport, it will however json.Encode the request body again (due to the mediaType being "application/json") which just escapes my json string (e.g. "{/"foo/":/"bar/"}). The Netbox API will then respond with a 400 error: PUT /dcim/devices/{id}/][400] dcim_devices_update default map[local_context_data:[JSON data must be in object form. Example: {“foo”: 123}]

The issue could be solved if the local_context_data parameter is an interface{}, so the runtime can correctly handle the json encoding! Was there a specific reason the have a string instead? Thanks

stefanhipfel avatar Jul 07 '21 18:07 stefanhipfel