Skip to content

Insert Before

Description

This operation inserts a new value before an existing value in a list.

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]/list/[key]/insert-before

where:

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

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:

{  
    "anchorValue": <any-JSON-value-that-exists-in-the-list>,  
    "valueToInsert": <any-JSON-value>  
}

where:

Argument                Description
"anchorValue" Value which is used as a position anchor.
"valueToInsert" New value that must be added to the list.

Response Body

The number of values in the list after the insertion operation.

Example

The example below inserts the "Apple" item right before the "Orange" item in the fruits list.

curl --location --request PUT "https://xxxx.backendless.app/api/hive/groceryStore/list/fruits/insert-before" \--header 'Content-Type: application/json' \--data-raw '{"anchorValue": "Orange", "valueToInsert": "Apple"}'

where:

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

Codeless Reference

list_api_insert_before

where:

Argument                Description
hive name Name of a hive where the operation is performed.
key name Key name identifying a list.
item New item to insert into the list.
before item Value which is used as a position anchor.

Returns he number of values in the list after the insertion operation.

Consider the following List storage:

list_api_example_insert_before_2

The example below inserts the value "Apple" before the "Orange" item in a list identified by the "fruits" key name:
list_api_example_insert_before


The list storage will look as shown below after the Codeless logic runs:
list_api_example_get_values_2