Reduce the Number of API Requests Made to Kintone Using IndexedDB
Overview
This article introduces how to locally store changes from one Kintone App, to populate values on another Kintone App using the IndexedDB API.
When designing solutions with Kintone via its APIs, the API request rate limits must be considered for high-throughput systems. There are many design patterns for limiting the number of API requests in applications, one of which is client-side storage. In this article, the Indexed Database API, a.k.a. IndexedDB, is used to locally store changes from one Kintone App to reduce the number of API calls made in another App.
What is IndexedDB
IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. Systems might use IndexedDB to store data locally on the client pc side, and then commit groups of changes in batch, or staggered over time in order to reduce the total number of requests made to the Kintone API.
General Flow
In this example, an office supply manufacturer keeps track of its products and the parts each product uses with the following Apps:
- In App A: Parts List, the parts data are added to a database, along with the product that used them.
- In App B: Product Management, when a product is added, a table of Lookup fields is automatically updated to show which parts the product uses.
Using a Javascript customization, the records from the Parts List App will be saved locally to the browser, which will later be used to update the Product Management App. When editing or adding a record to the Product Management App, an API call is made to the Parts List App to check when the last update occurred. If there have been no updates, the local database is used. If the local database is outdated, it will be updated and then referenced by the Lookup field.
Why this is valuable
Normally, adding or editing a product in the Product Management App would require X times the number of API calls, where X is the number of Lookup fields. This also needs to be entered manually.
In Kintone, the total number of API requests available per App per day is 10,000. For more information, refer to the following article on the help site:
List of Limit Values
For this example, if each product has 3 parts, it would take 3,333 products to reach this limit. However, in large organizations with many related fields and multiple users editing the data, this limit could be reached or cause a slowdown on the server before reaching it. This customization offloads CPU workload from the server to each user's local environment. The core concepts in this article should be widely applicable to complex Apps with many dependencies.
Required Environments
In addition to a Kintone environment, the following will also need to be prepared:
- This guide uses the Google Chrome browser. However, the IndexedDB API has been available in recent versions for all major browsers.
- Node.js v22.13 (LTS).
Initial Setup
This section describes how to set up two Kintone Apps. One of the Apps is then customized using JavaScript.
Create Two Kintone Apps
First, create a new Kintone App. Set the title to "Parts List" and set the fields as follows.
Field Type | Field Name | Field Code | Notes |
---|---|---|---|
Text | Part Number | Part_Number | Unique field. Check the Prohibit duplicate values option. |
Text | Part Name | Part_Name | |
Text | Related Product Name | Related_Product_Name | |
Date and time | Updated datetime | Updated_datetime | Check the Required field option. |
Next, create another App and set the title as "Product Management". Then set the fields as follows.
Field Type | Field Name | Field Code | Notes |
---|---|---|---|
Text | Product Name | Product_Name | |
Table | Parts | Parts | See the table below for the fields to place inside. |
Date and Time | Updated datetime | Updated_datetime | Check the Required field option. |
Set the following fields and settings for the Parts table.
Field Type | Field Name | Field Code | Notes |
---|---|---|---|
Lookup | Part Number | Part_Number | Set the following settings:
|
Text | Part Name | Part_Name |
Add Sample Data to The Parts List App
Using the Kintone GUI, add a few records to the Parts List App. For ease of understanding in this example, variations on the following record may be useful:
Part Number | Part Name | Related Product Name | Date and Time |
---|---|---|---|
bc-01 | Blue Pen Cap | Blue Pen | -- |
bi-01 | Blue Pen Ink | Blue Pen | -- |
rc-01 | Red Pen Cap | Red Pen | -- |
ri-01 | Red Pen Ink | Red Pen | -- |
Sample JavaScript Code
Prepare the following JavaScript code in a text editor and navigate to the Product Management App's App settings. Upload the file into the Upload JavaScript for PC option of the JavaScript and CSS Customization settings with reference to the following guide on the Kintone Help Site:
Customizing an App Using JavaScript and CSS
|
|
After adding the customization JavaScript file, update the App Settings via the Update App button.
Test the Scenario
Create a record in the Product Management App to check the browser console and confirm that the customization works.
The customization has used internal API requests to retrieve and store the Parts List App records. This can be confirmed in the Browser Dev Tools > Application > IndexedDB > KintoneDatabase > AppId: {your App ID}.
Typing one of the related products from the Parts List App into the "Product Name" field will automatically lookup the related parts. This time, try adding "Blue Pen".
Note
At this point, there are a total of 4 internal API requests. This includes one request for the product lookup, one for each related part, and an additional request for the customization. This means there is one more API request compared to a normal, non-customized app.
Next, create another record and type "Red Pen" into the "Product Name" field. The parts are automatically looked up, leading to the same end-user experience.
Note
When creating the second record, the total number of API requests is 2: one to check if the parts list database has been updated recently and another for the "Product Name" lookup field. Without this customization, this Product would have used another 3 internal API requests, leading to a total saving of 1 API request. This number would be larger, if our pens had more than two parts.
The total API Savings can be expressed as: Total API Savings = (Total Lookup Fields per Product - 1) * Number of Users
For example, if a larger team of 10 people were managing 20 products, with a random variation of 3 - 5 parts each, the total API request savings per product added would equal 30 API requests saved, as opposed to 50 requests for the non-customized App.