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:
- JSON
- XML
{
"token": "abcdefghijklmnqrstuvwxyz",
"db_id": 24,
"profile_id": "5a5b64a969d4265b958b9ac3",
"data": {
"checks": {
"action": "incr",
"value": 1000
},
"returns": {
"action": "incr",
"value": -1000
}
}
}
<xml>
<token>abcdefghijklmnqrstuvwxyz</token>
<db_id>1</db_id>
<profile_id>6613c4754a5d12bd6cc0915f</profile_id>
<data>
<checks>
<action>incr</action>
<value>1000</value>
</checks>
<returns>
<action>incr</action>
<value>-1000</value>
</returns>
</data>
</xml>
profiles/update adds tags to profile "category" field:
- JSON
- XML
{
"token": "abcdefghijklmnqrstuvwxyz",
"db_id": 1,
"profile_id": "5a5b64a969d4265b958b9ac3",
"data": {
"category": {
"action": "add",
"value": [
"cars",
"cats"
]
}
}
}
<xml>
<token>abcdefghijklmnqrstuvwxyz</token>
<db_id>1</db_id>
<profile_id>6613c4bf4a5d12bd6cc0916b</profile_id>
<data>
<category>
<action>add</action>
<value array='true'>cars</value>
<value>cats</value>
</category>
</data>
</xml>
An example of a profiles/update request that will update the "x" field in an object:
- JSON
- XML
{
"token": "abcdefghijklmnqrstuvwxyz",
"db_id": 1,
"profile_id": "6613c4bf4a5d12bd6cc0916b",
"data": {
"myObject": {
"action": "upsert",
"value": "y",
"submatch": "x"
}
}
}
<xml>
<token>2fefb577533d4cae919350c450755239</token>
<db_id>1</db_id>
<profile_id>66102b984a5d12bd6cc0912f</profile_id>
<data>
<myObject>
<action>upsert</action>
<value>y</value>
<submatch>x</submatch>
</myObject>
</data>
</xml>
profiles/update sets a new value for all elements of the object that contain the specified property (submatch):
Request
- JSON
- XML
{
"token": "abcdefghijklmnqrstuvwxyz",
"db_id": 1,
"profile_id": "66102b984a5d12bd6cc0912f",
"data": {
"myObject": {
"action": "upsert",
"value": {
"x": "y",
"z": 1
},
"submatch": "x"
}
}
}
<xml>
<token>abcdefghijklmnqrstuvwxyz</token>
<db_id>1</db_id>
<profile_id>66102b984a5d12bd6cc09132</profile_id>
<data>
<myObject>
<action>upsert</action>
<value>
<x>y</x>
<z>1</z>
</value>
<submatch>x</submatch>
</myObject>
</data>
</xml>
Object
- JSON
- XML
{
{
"A": 1,
"x": false,
},
{
"B": "test"
},
{
"x": "test",
"C": true
}
}
<xml>
<value>
<A>1</A>
<x>false</x>
</value>
<value>
<B>test</a>
</value>
<value>
<x>test</x>
<c>true</c>
</value>
</xml>
Updated object
- JSON
- XML
{
{
"A": 1,
"x": {"x": "y", "z": 1},
},
{
"B": "test"
},
{
"x": {"x": "y", "z": 1},
"C": true
}
}
<xml>
<value>
<A>1</A>
<x>
<m>y</m>
<z>1</z>
</x>
</value>
<value>
<B>test</B>
</value>
<value>
<x>
<m>y</m>
<z>1</z>
</x>
<c>true</c>
</value>
</xml>
If fields with type object
and object_arr
do not have a property that you want to change, this property is created automatically.