Skip to main content

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:

actionUsageField typevalue
setSet is a default operator for request parameters*Any field value
unsetDeletes a field from a profile (for all fields except email)*No value
incrIncreases field value. Integer type fields onlyint, floatInteger number
addAdds tags to a profile fieldtags, arr_objectArray of strings
deleteDeletes tags from a profile fieldtags, arr_objectArray of strings
upsertSets the value from the value field to the property specified in the submatch fieldobjectDepends on the field type
info

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
}
}
info

If fields with type object and object_arr do not have a property that you want to change, this property is created automatically.