Skip to main content

Replace element

Description#

Use a HTTP POST request to replace a top level element from an array or key from an object in a resource. The request returns the updated resource.

Request#

HTTP Method: POST

ParameterDescription
idThe ID of the resource.
keyThe object key to replace if replacing from an object.
indexThe index of the element to replace if replacing from an array (with indexes starting at 0).
valueThe new value to replace the existing element with

Sample request#

Sample request for an array element

curl -X POST \  https://<tenant-domain>/api/v1/global_resources/<resource-id>/replace \  -H 'content-type: application/json' \  -H 'x-user-email: <email-address>' \  -H 'x-user-token: <api-token>' \  -d '{        "index": "0",        "value": "new-value"    }'

Sample request for an object key

curl -X POST \  https://<tenant-domain>/api/v1/global_resources/<resource-id>/replace \  -H 'content-type: application/json' \  -H 'x-user-email: <email-address>' \  -H 'x-user-token: <api-token>' \  -d '{        "key": "foo",        "value": "new-value"    }'

Response#

A successful request will return the updated resource value

Sample response#

{  "id": 9,  "name": "a json resource",  "value": "{\"foo\":\"new-value\"}",  "user_id": 1,  "created_at": "2020-02-05T20:40:32.313Z",  "updated_at": "2020-02-05T20:55:18.239Z"}