Database fields functional update
When you use requests to update profile fields, you can include functions in field values.
A function here is a set of an operator and a value:
{
"action": "set",
"value": "x",
}
Action operator can be:
action | Usage | Field type | value |
---|---|---|---|
set | Set is a default operator for request parameters | * | Any field value |
unset | Deletes a field from a profile (for all fields except email ) | * | No value |
incr | Increases field value. Integer type fields only | int, float | Integer number |
add | Adds tags to a profile field | tags, arr_object | Array of strings |
delete | Deletes tags from a profile field | tags, arr_object | Array of strings |
upsert | Sets the value from the value field to the property specified in the submatch field | object | Depends on the field type |
For object
and arr_object
data types, you must pass the value
and submatch
fields.
submatch
is the path to the property whose value needs to be updated.
Request examples
profiles/update increases one value and decreases the other. The same operator with different value sign is used:
{
"db_id": 24,
"profile_id": "5a5b64a969d4265b958b9ac3",
"data": {
"checks": {
"action": "incr",
"value": 1000
},
"returns": {
"action": "incr",
"value": -1000
}
}
}
profiles/update adds tags to profile "category" field:
{
"db_id": 24,
"profile_id": "5a5b64a969d4265b958b9ac3",
"data": {
"category": {
"action": "add",
"value": ["cars", "cats"]
}
}
}
An example of a profiles/update request that will update the "x" field in an object:
{
"token": "abcdefghijklmnqrstuvwxyz",
"db_id": 24,
"profile_id": "5a5b64a969d4265b958b9ac3",
"data": {
"myObject": {
"action": "upsert",
"value": "y",
"submatch": "x",
},
}
}
profiles/update sets a new value for all elements of the object that contain the specified property (submatch):
Request
{
"token": "abcdefghijklmnqrstuvwxyz",
"db_id": 24,
"profile_id": "5a5b64a969d4265b958b9ac3",
"data": {
"myArrOfObject": {
"action": "upsert",
"value": {"x": "y", "z": 1},
"submatch": "x",
},
}
}
Object
{
{
"A": 1,
"x": false,
},
{
"B": "test"
},
{
"x": "test",
"C": true
}
}
Updated object
{
{
"A": 1,
"x": {"x": "y", "z": 1},
},
{
"B": "test"
},
{
"x": {"x": "y", "z": 1},
"C": true
}
}
If fields with type object
and object_arr
do not have a property that you want to change, this property is created automatically.