PATCH seems not to be working?
A PATCH operation should update a specified field. a PUT operation will update “all the fields” and you’ll have to supply all the json.
I just issued a curl to get my :
curl -sk -X GET -H "zt-session: $token" $mycontroller/edge/management/v1/configs | jq .
to get id: 5LwHA6zG0lxSPrENcThzeL
.
Then I did a GET on that config:
curl -sk -X GET -H "zt-session: $token" $mycontroller/edge/management/v1/configs/5LwHA6zG0lxSPrENcThzeL | jq .data[]
which gives me valid json:
curl -sk -X GET -H "zt-session: $token" $baseurl/edge/management/v1/configs/5LwHA6zG0lxSPrENcThzeL | jq .
{
"data": {
"_links": {
"self": {
"href": "./configs/5LwHA6zG0lxSPrENcThzeL"
}
},
"createdAt": "2023-08-20T03:12:06.977Z",
"id": "5LwHA6zG0lxSPrENcThzeL",
"tags": {},
"updatedAt": "2023-08-20T03:12:06.977Z",
"configType": {
"_links": {
"self": {
"href": "./config-types/NH5p4FpGR"
}
},
"entity": "config-types",
"id": "NH5p4FpGR",
"name": "host.v1"
},
"configTypeId": "NH5p4FpGR",
"data": {
"address": "apache-exporter",
"listenOptions": {
"bindUsingEdgeIdentity": true
},
"port": 9117,
"protocol": "tcp"
},
"name": "prometheus.host.v1"
},
"meta": {}
}
So I tried to PATCH ‘address’:
curl -sk -X PATCH -H "Content-Type: application/json" -H "zt-session: $token" $mycontroller/edge/management/v1/configs/5LwHA6zG0lxSPrENcThzeL -d '{"data": {"address": "new_address"}}' | jq .
The controller returns:
{
"error": {
"cause": {
"field": "(root)",
"reason": "(root) is invalid: (root): Must validate \"else\" as \"if\" was not valid",
"value": "map[address:new_address]"
},
"code": "COULD_NOT_VALIDATE",
"message": "The supplied request contains an invalid document or no valid accept content were available, see cause",
"requestId": "zOKuMNPmP"
},
"meta": {
"apiEnrollmentVersion": "0.0.1",
"apiVersion": "0.0.1"
}
}
Using PUT Works
So I made a PUT.txt file (for easy use in curl):
{
"createdAt": "2023-08-20T03:12:06.977Z",
"id": "5LwHA6zG0lxSPrENcThzeL",
"tags": {},
"updatedAt": "2023-08-20T03:12:06.977Z",
"configType": {
"_links": {
"self": {
"href": "./config-types/NH5p4FpGR"
}
},
"entity": "config-types",
"id": "NH5p4FpGR",
"name": "host.v1"
},
"configTypeId": "NH5p4FpGR",
"data": {
"address": "updated-apache-exporter",
"listenOptions": {
"bindUsingEdgeIdentity": true
},
"port": 9117,
"protocol": "tcp"
},
"name": "prometheus.host.v1"
}
Then used curl to PUT that back:
curl -sk -X PUT -H "Content-Type: application/json" -H "zt-session: $token" $baseurl/edge/management/v1/configs/5LwHA6zG0lxSPrENcThzeL -d @PUT.txt
Afterwards, you can see my config address updated:
curl -sk -X GET -H "zt-session: $token" \
$baseurl/edge/management/v1/configs/5LwHA6zG0lxSPrENcThzeL \
| jq .data.data.address
"updated-apache-exporter"
I think we need @andrew.martinez to weigh on this one. PATCH wouldn’t work for me.