Update multiple records in a single REST call
Why would you want to update multiple records in a single REST call?
API Rate Limits - Many APIs enforce rate limits on the number of requests a client can make. Updating multiple records in a single call reduces the number of API requests made and avoids hitting rate limits.
Improved performance - Updating multiple records in a single call reduces the round-trip time between the client and server, improving overall performance.
How does this work
To update multiple records in a single REST call, use the execute-entities action to call the REST function.
It is important to know what method your function call is using. For example, using PUT will overwrite all values in the record, while using PATCH will only update the new or changed values in the record.
There are two ways to configure the
execute-entitiesaction.Use
parametersfor values that must be evaluated statically across all the records.Values that are dynamic per record are configured in the
dataproperty.
actions:
- children:
- type: action.execute-entities
options:
title: Update Record
provider: DATA_PROVIDER_REST
entity: customers
method: update
function: rest-update-customer
# All records will be updated with Bronze tag
# CustomerType is the same (static) across all records
parameters:
customerType: Bronze
data:
customerType: Bronze actions:
- children:
- type: action.execute-entities
options:
title: Update Record
provider: DATA_PROVIDER_REST
entity: customers
method: update
goBack: stay
function: rest-update-customer
# All records will be updated dynamically per record.
# Define the properties to be updated in the records.
# Data must include all required properties on the record
# in the datasource.
parameters: [email protected].{"id":id, "firstName":firstName, "lastName":lastName, "companyName":companyName}[]
data: [email protected].{"id":id, "firstName":firstName, "lastName":lastName, "companyName":companyName}[] The properties defined in the
dataproperty are determined by the REST call. This means that if the only required property is id you can simply use id, such as:data: [email protected].{"id":id}[]However, if you have multiple required properties in the REST call you need to define all of them under data, such as:data: [email protected].{"id":id, "firstName":firstName, "lastName":lastName, "companyName":companyName}[]Using JSONata expressions can further simplify updating mutiple records, for example, using the following expression will update all records in the customer list to Bronze.
data: =ctx.datasources.customers ~> | $ | { "customerType": "Bronze "} |See the Jsonata transform operator for more information.
Scenario
This example lists all customers without a label (CustomerType property). Using the execute-entities action all customers without a label are updated to show a Bronze label.

How is this scenario configured
The customer list is loaded from the customers datasource, the query returns all records WHERE
customerTypeIS NULL.An
execute-entitiesaction is configured to update multiple records with a single REST call. The update function calls the REST APIs PATCH operation.The
execute-entitiesaction is configured usingparametersto update thecustomerTypeproperty to Bronze. This is a static value and will be the same for all the customers in the list.The
execute-entitiesaction is configured usingdatato define the required REST properties for the customers' records. In this example,id,firstName,lastNameandcompanyNameare required parameters in the REST function.When the Update records button is pressed all customers with no
customerTypeproperty (label) is updated to Bronze.
REST API
URL
https://[your_rest_service]/api/customers
Operation/Method
PATCH
Function
The REST APIs PATCH operator is used in a Jigx function with body parameters to specify the exact columns to be updated for the record. The inputTransform specifies how the data should be structured or formatted when being sent to the REST service. This transformation process ensures that the data adheres to the expected schema or format required by the REST service for processing the request. Take note of the required parameters in the function as these are required in the data property of the execute-entities action.
Action (global)
Create a load-data.jigx file under the actions folder. This file is configured with an action that syncs the data from the REST service, by calling the function, to the local Sqlite table. The action file is referenced in the index.jigx file to load the data when the app is opened or is in focus on the device.
Jig (screen)
Create a customers list jig where the customer datasource query is configured to return all customers with no label.
Add an
execute-entitiesaction to call the function that will update all the customer records in the local table (usingmethod: update) and in the REST service (function: rest-update-customer). Define theparameterproperty to update thecustomerTypeproperty to Bronze. Configuring thedataproperty is used to configure the properties that are required to update all records in the list.
An alternate option would be to use the following expression under data, removing the need for functionParameter: data: =ctx.datasources.customers ~> | $ | { "customerType": "Bronze "} |
Index
For performance and offline support the data is synced from the REST service as soon as the app is opened or receives focus. This is achieved by calling the global action in the OnFocus and onLoad events.
Updating multiple images & REST calls in a single REST call
When you have multiple images to upload in multiple REST calls, you can use the following in your configuration.
Use the
$map()function to iterate over the image array.Use
queueOperation: replacefor batch operations.Data structure: Each mapped item should contain the necessary fields for your REST endpoint.
Last updated
Was this helpful?