The "setValues" action stores one or more key-value pairs in the server. The key is a UTF-8 string up to 128 bytes in length. The value is a JSON object up to 2 gigabytes. If the key does not exist, the action creates it. If the key exists, the action updates it. Each key has its own value.
How to use "setValues"
Use the "keyStore" property to specify the keystore for the key-value pairs you want to create or update. Include one or more key-value pair objects in the "keyValuePairs" property. Use the "key" and "value" properties to define each key-value pair. The key is a string and the value is JSON. A JSON value can be an object, array, string, number, true, false, or null.
When using the "role" keystore, you must set the "roleName" property to the name of the role that owns the key-value pair. The action returns an error when the current user does not have the specified role. An administrator account may set and get values for any role.
When using the "user" keystore, the action automatically uses the session's username to limit which keys the user can set and retrieve. When an administrator account runs the action, it can optionally use the "username" property to specify the user that owns the keys. This allows an elevated account to create and modify keys for other accounts.
If the response contains "errorCode": 0, then the request succeeded. No additional information is included in the response to optimize network communication speed. If there is an error, the "errorMessage" property describes the problem.
Tip You may optionally create a key hierarchy using the slash / character or any other string you prefer. Each level in the hierarchy should end with the delimiter string. For instance,
"color/"acts as a parent to keys like"color/red"and"color/green". You may assign a value to any key string, including those that are parents of other keys, such as"color/".
Request examples
Global keystore
{
"api": "db",
"action": "setValues",
"params": {
"keyStore": "global",
"keyValuePairs":
[
{
"key": "myKey",
"value": {"my": "value"}
},
{
"key": "myApp/queries/My Favorite",
"value": {"savedQuery": "favorite = 1"}
},
{
"key": "myApp/queries/Find Errors",
"value": {"savedQuery": "error = 1"}
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Role keystore
The action uses the specified role and returns an error if the current session's account does not have that role. An administrator account may create and modify key-value pairs for any role.
{
"api": "db",
"action": "setValues",
"params": {
"keyStore": "role",
"roleName": "operator",
"keyValuePairs":
[
{
"key": "myKey",
"value": 1
},
{
"key": "myApp/queries/My Favorite",
"value": {"savedQuery": "favorite = 1"}
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
User keystore
The action automatically uses the session's username.
{
"api": "db",
"action": "setValues",
"params": {
"keyStore": "user",
"keyValuePairs":
[
{
"key": "myKey",
"value": "myValue"
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
User keystore using elevated privileges
When an administrator account runs the action, it can optionally use the "username" property to specify the account of the key-value pair. This allows an elevated account to create and modify key-value pairs for other accounts.
{
"api": "db",
"action": "setValues",
"params": {
"keyStore": "user",
"username": "someone_else",
"keyValuePairs":
[
{
"key": "myKey",
"value": "someone_else_value"
},
{
"key": "myApp/queries/My Favorite",
"value": {"savedQuery": "favorite = 1"}
}
]
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
Global keystore
{
"result": {},
"authToken": "replaceWithAuthTokenFromCreateSession",
"errorCode": 0,
"errorMessage": ""
}Role keystore
{
"result": {},
"authToken": "replaceWithAuthTokenFromCreateSession",
"errorCode": 0,
"errorMessage": ""
}User keystore
{
"result": {},
"authToken": "replaceWithAuthTokenFromCreateSession",
"errorCode": 0,
"errorMessage": ""
}User keystore using elevated privileges
{
"result": {},
"authToken": "replaceWithAuthTokenFromCreateSession",
"errorCode": 0,
"errorMessage": ""
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
keyStore |
The
|
Required - No default value | string enum |
|
keyValuePairs |
The "keyValuePairs" property contains objects that represent a key-value pair and contain "key" and "value" properties, such as { "key": "k1", "value": 1 }. |
Required - No default value | array of key-value objects | |
|
keyValuePairs .key |
The "key" property is part of an optional key-value object that is defined in an array in the "userProperties" property. It is a user-defined string value. |
Optional with default of
Required in the Key-Value API |
string | 1 to 128 bytes |
|
keyValuePairs .value |
The
In Key-Value actions, the required |
Required - No default value | string |
|
roleName |
The
|
Required when "keystore": "role"
|
string | 1 to 64 bytes |
username |
The
In
In Key-Value actions, the
|
Required - No default value
Optional with default of the account name of the currently logged-in user for Key-Value actions
|
string | 1 to 64 bytes |