Set Key Value
Last updated
Was this helpful?
Last updated
Was this helpful?
This is pre-built Action located under the @Generic Element Name. It instructs the Avo Assure Client to set the value of the specified key from the input and save the result in the given output variable.
Syntax:
Input: <input_json>;<block_key_name>;<block_count>;<key_name>;<key_value>
Output: <Dynamic Variable>;<Dynamic Variable>(Optional)
Usecase/Example:
Scenario: Updating User Preferences in a Web Application
In a web application, users can customize their settings, such as notification preferences and theme choices. When users make changes to their preferences, the application must send a request to the backend API to save these updates. This scenario tests the functionality of setting key values in the
payload to ensure that the application accurately reflects the user's desired settings when making the API call.
Testing Example:
Input:
API Endpoint: `POST /api/users/preferences`
Initial Payload:
json
{
"userId": "56789",
"notifications": {
"email": true,
"sms": false
},
"theme": "light"
}
```
Using the Action:
Use the action `set key value` to update the following:
Set `notifications.sms` to `true` (enabling SMS notifications).
Set `theme` to `"dark"` (changing the user interface theme).
Expected Result:
- Updated Payload after actions:
```json
{
"userId": "56789",
"notifications": {
"email": true,
"sms": true
},
"theme": "dark"
}
Validation: The API response confirms that the user preferences were updated successfully, demonstrating that the "Set Key Value" functionality works as intended.
Output: The resulting beautified content is stored in the {result} output variable, which can be utilized for display or other purposes.