Skip to content

Overwrite Current Value

Description

This operation overwrites the value of a key.

It is almost identical to Set Value By Key Name operation, but provides an additional parameter to control the overwrite process more flexibly.

Method

PUT

Endpoint URL

Important

Make sure to replace xxxx in the domain name in the request specification below to the one assigned to your application.

https://xxxx.backendless.app/api/hive/[hive-name]/map/[key]/set-with-overwrite/[key-name]

where:

Argument                Description
[hive-name] Name of a hive where the operation is performed.
[key] Key name identifying a map.
[key-name] Key name identifying a key-value pair.

Request Headers

Content-Type:application/json

where:

Argument                Description
Content-Type Must be set to application/json. This header is mandatory.

Request Body

The request body must be a JSON object with the structure shown below:

{  
  "value": <any-value>,  
  "overwrite": <boolean>   // defaults to true  
}

where:

Argument                Description
"value"  Specify a valid JSON data type to replace an existing value.
"overwrite" When set to true, forces the rename operation and name overwrite.

Response Body

The return value depends on the operation behavior:

When the "overwrite" parameter is set to true:

Scenario 1: If the specified key is found, the operation overwrites the value and returns false. The false is returned to indicate that the new key-value pair was not created, but only the existing key-value pair was updated.

Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true.

When the "overwrite" parameter is set to false:

Scenario 1: If the specified key is found, the operation does not overwrite the value, but only returns false indicating that the value was not overwritten and the new-key value pair was not created.

Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true.

Example

The example below overwrites the current value of the Oranges key with a new value 1.29. The invocation returns false indicating that this value is updated. As you can see, the "overwrite" parameter is set to true, hence the operation overwrites the value.

curl --location --request PUT "https://xxxx.backendless.app/api/hive/groceryStore/map/fruits/set-with-overwrite/Oranges" \--header 'Content-Type: application/json' \--data-raw '{"value": 1.29,"overwrite": true}'

where:

Argument                Description
groceryStore Name of a hive where the operation is performed.
fruits Key name identifying a map.

Codeless Reference

map_api_set_value_with_overwrite

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a map.
object key name Key name identifying a key-value pair.
value A value for a key.
overwrite When set to true, forces the rename operation and name overwrite.

The return value depends on the operation behavior:

When the overwrite parameter is set to true:

Scenario 1: If the specified key is found, the operation overwrites the value and returns false. The false is returned to indicate that the new key-value pair was not created, but only the existing key-value pair was updated.

Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true.

When the overwrite parameter is set to false:

Scenario 1: If the specified key is found, the operation does not overwrite the value, but only returns false indicating that the value was not overwritten and the new-key value pair was not created.

Scenario 2: If the specified key is not found, then the operation creates a new value pair and returns true.

Consider the following Map storage:
map_apI_example_map_store

The example below overwrites the current value of the "Oranges" key with a new value 1.29.

map_example_api_set_value_with_overwrite

The map will look as shown below after the Codeless logic runs:
map_apI_example_map_store_5