How to update the value of a Field in a specific Record.
When you submit a Record in Risk Cloud, all of the Field values you have selected or input are saved on that Record. In this article we will learn how to update a specific Field's value in a specific Record using the Risk Cloud API. In this example we will cover how to update a Select Field. The API requests & responses seen in this article will differ slightly based on the Field type that is being updated.
Updating a Field on a Record
Within a Step, we have a Field named "Severity." Severity has selectable values of "Low," "Medium," and "High."
Let's assume that you have created a Record and selected a severity of "Medium," but would like to change that to "High." We are able to do this with some requests to the Risk Cloud API.
First, we must obtain the values already on the Record, which can be done via the following GET request.
Note: The "record_id" to use in your GET request will be the unique string of numbers and letters in the record URL. In our case, the URL of the record we would like to update is https://your-company.logicgate.com/records/srAIdk3c. The "record_id" we will use is "srAIdk3c."
Obtaining proper API authentication
Prior to any interaction with Risk Cloud’s APIs we will need to set the authorization header. Instructions on how this can be accomplished can be found here.
Request Type: GET
URL: https://your-company.logicgate.com/api/v1/valueMaps?record=RECORD_ID
Response:
{
"srAIdk3c": {
"id": "k9IYrkst",
"active": true,
"created": 1554232752610,
"updated": 1554233219059,
"step": null,
"user": null,
"currentValues": [
{
"discriminator": "Common",
"id": "ziJtKBiZ",
"active": true,
"created": 1554232752610,
"updated": null,
"valueType": "Common",
"textValue": "Medium",
"numericValue": 1,
"isDefault": false,
"archived": false,
"priority": 2,
"empty": false,
"default": false,
"fieldId": null
}
],
"field": {
"fieldType": "SELECT",
"id": "srAIdk3c",
"active": true,
"created": 1554228320342,
"updated": 1554232752610,
"name": "Severity",
"label": "Severity Level",
"tooltip": null
},
"record": null,
"node": null,
"expressionResult": 2,
"assignment": null
}
}
The response is a key value pair where the key is the ID of the field and the value is the selected value. The most important part of this response is the currentValues array. The object inside this array is what is currently selected, and what we need to update.
Because we are updating a "select" field, we should first understand what all of our options are! We can do this by submitting a GET request to the "field" endpoint. You can find your field_id in the response above within the "field" object, or by calling the fields/workflow/WORKFLOW_ID endpoint.
Request Type: GET
URL: https://your-company.logicgate.com/api/v1/fields/srAIdk3c
Response:
{
"fieldType": "SELECT",
"id": "srAIdk3c",
"name": "Severity",
"label": "Severity Level",
"tooltip": null,
"currentValues": [
{
"discriminator": "Common",
"id": "IXxbj7uk",
"valueType": "Common",
"textValue": "Low",
"numericValue": 1,
"isDefault": false,
"archived": false,
"priority": 3,
"empty": false,
"default": false,
"fieldId": "srAIdk3c"
},
{
"discriminator": "Common",
"id": "ziJtKBiZ",
"valueType": "Common",
"textValue": "Medium",
"numericValue": 1,
"isDefault": false,
"archived": false,
"priority": 2,
"empty": false,
"default": false,
"fieldId": "srAIdk3c"
},
{
"discriminator": "Common",
"id": "fwy1ntpD",
"valueType": "Common",
"textValue": "High",
"numericValue": 1,
"isDefault": false,
"archived": false,
"priority": 1,
"empty": false,
"default": false,
"fieldId": "srAIdk3c"
}
],
...
}
The currentValues array contains all of the selectable options for Severity select field in the form of objects. We can choose any object in the array to be our new selected value, and for this example we will be choosing the value of "High."
In the following POST request, use the "record_id" for the specific record that you want to update.
Request Type: POST
URL: https://your-company.logicgate.com/api/v1/valueMaps?record=RECORD_ID
Request:
{
"id": "k9IYrkst",
"active": true,
"created": 1554232752610,
"updated": 1554233219059,
"step": null,
"user": null,
"currentValues": [
{
"discriminator": "Common",
"id": "fwy1ntpD",
"valueType": "Common",
"textValue": "High",
"numericValue": 1,
"isDefault": false,
"archived": false,
"priority": 1,
"empty": false,
"default": false,
"fieldId": "srAIdk3c"
}
],
"field": {
"fieldType": "SELECT",
"id": "srAIdk3c",
"active": true,
"created": 1554228320342,
"updated": 1554244721428,
"name": "Severity",
"label": "Severity Level",
"tooltip": null
},
"record": null,
"node": null,
"expressionResult": 2,
"assignment": null
}
Notice that we have replaced the object in the currentValues array with the value object for "High." This serves to update the selected value from our original value of "medium" to our new desired value of "High."
Response:
{
"id": "k9IYrkst",
"currentValues": [
{
"discriminator": "Common",
"id": "fwy1ntpD",
"valueType": "Common",
"textValue": "High",
"numericValue": 1,
"isDefault": false,
"archived": false,
"priority": 1,
"empty": false,
"default": false,
"fieldId": null
}
],
"field": {
"fieldType": "SELECT",
"id": "srAIdk3c",
"name": "Severity",
"label": "Severity Level",
"tooltip": null
},
"node": {
"stepType": "End",
"id": "lkePaPYj"
},
"expressionResult": 10
}
We can see the severity level has been updated to "High."
For more information about the Risk Cloud API you can read our Developer Center.
Comments
0 comments
Please sign in to leave a comment.