diff --git a/packages/rest-api-client/docs/record.md b/packages/rest-api-client/docs/record.md
index 56e950b24d..9266bc63e8 100644
--- a/packages/rest-api-client/docs/record.md
+++ b/packages/rest-api-client/docs/record.md
@@ -299,6 +299,7 @@ If you'd like to update over 100 records, please consider using [updateAllRecord
| Name | Type | Required | Description |
| ------------------------- | :--------------: | :-------------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The app ID. |
+| upsert | Boolean | No | Whether to execute in UPSERT mode. If true is specified, it will be executed in UPSERT mode. |
| records | Array | Yes | Holds an array of objects that include `id`/`updateKey`, `revision` and `record` objects.
Up to 100 records can be specified. |
| records[].id | Number or String | Conditionally
Required | The record ID of the record to be updated. Required, if `updateKey` will not be specified. |
| records[].updateKey | Object | Conditionally
Required | The unique key of the record to be updated. Required, if `id` will not be specified. To specify this field, the field must have the "Prohibit duplicate values" option turned on. |
@@ -309,11 +310,12 @@ If you'd like to update over 100 records, please consider using [updateAllRecord
#### Returns
-| Name | Type | Description |
-| ------------------ | :----: | ------------------------------------------------------------------------------ |
-| records | Array | Holds an array of objects that include `id` and `revision` of updated records. |
-| records[].id | String | The ID of the record. |
-| records[].revision | String | The revision number of the record. |
+| Name | Type | Description |
+| ------------------- | :----: | ---------------------------------------------------------------------------------------------------------------------------------- |
+| records | Array | Holds an array of objects that include `id` and `revision` of updated records. |
+| records[].id | String | The ID of the record. |
+| records[].revision | String | The revision number of the record. |
+| records[].operation | String | The operation performed on the record. This is output when UPSERT mode is enabled. `INSERT` : New registration / `UPDATE` : Update |
#### Reference
@@ -332,6 +334,7 @@ For more information, please see [an example of KintoneAllRecordsError](errorHan
| Name | Type | Required | Description |
| ------------------------- | :--------------: | :-------------------------: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app | Number or String | Yes | The app ID. |
+| upsert | boolean | No | Whether to execute in UPSERT mode. If true is specified, it will be executed in UPSERT mode. |
| records | Array | Yes | Holds an array of objects that include `id`/`updateKey`, `revision` and `record` objects.
Over 100 records can be specified. |
| records[].id | Number or String | Conditionally
Required | The record ID of the record to be updated. Required, if `updateKey` will not be specified. |
| records[].updateKey | Object | Conditionally
Required | The unique key of the record to be updated. Required, if `id` will not be specified. To specify this field, the field must have the "Prohibit duplicate values" option turned on. |
@@ -342,11 +345,12 @@ For more information, please see [an example of KintoneAllRecordsError](errorHan
#### Returns
-| Name | Type | Description |
-| ------------------ | :----: | ------------------------------------------------------------------------------ |
-| records | Array | Holds an array of objects that include `id` and `revision` of updated records. |
-| records[].id | String | The ID of the record. |
-| records[].revision | String | The revision number of the record. |
+| Name | Type | Description |
+| ------------------- | :----: | ---------------------------------------------------------------------------------------------------------------------------------- |
+| records | Array | Holds an array of objects that include `id` and `revision` of updated records. |
+| records[].id | String | The ID of the record. |
+| records[].revision | String | The revision number of the record. |
+| records[].operation | String | The operation performed on the record. This is output when UPSERT mode is enabled. `INSERT` : New registration / `UPDATE` : Update |
### deleteRecords
diff --git a/packages/rest-api-client/src/client/RecordClient.ts b/packages/rest-api-client/src/client/RecordClient.ts
index 36de80a05c..3ad0a69ef5 100644
--- a/packages/rest-api-client/src/client/RecordClient.ts
+++ b/packages/rest-api-client/src/client/RecordClient.ts
@@ -10,6 +10,7 @@ import type {
CommentID,
Comment,
Mention,
+ UpdateRecordsForResponse,
} from "./types";
import { BaseClient } from "./BaseClient";
@@ -167,6 +168,7 @@ export class RecordClient extends BaseClient {
public updateRecords(params: {
app: AppID;
+ upsert?: boolean;
records: Array<
| { id: RecordID; record?: RecordForParameter; revision?: Revision }
| {
@@ -175,7 +177,9 @@ export class RecordClient extends BaseClient {
revision?: Revision;
}
>;
- }): Promise<{ records: Array<{ id: string; revision: string }> }> {
+ }): Promise<{
+ records: UpdateRecordsForResponse;
+ }> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "records",
});
@@ -415,6 +419,7 @@ export class RecordClient extends BaseClient {
public async updateAllRecords(params: {
app: AppID;
+ upsert?: boolean;
records: Array<
| { id: RecordID; record?: RecordForParameter; revision?: Revision }
| {
@@ -423,13 +428,16 @@ export class RecordClient extends BaseClient {
revision?: Revision;
}
>;
- }): Promise<{ records: Array<{ id: string; revision: string }> }> {
+ }): Promise<{
+ records: UpdateRecordsForResponse;
+ }> {
return this.updateAllRecordsRecursive(params, params.records.length, []);
}
private async updateAllRecordsRecursive(
params: {
app: AppID;
+ upsert?: boolean;
records: Array<
| { id: RecordID; record?: RecordForParameter; revision?: Revision }
| {
@@ -440,11 +448,13 @@ export class RecordClient extends BaseClient {
>;
},
numOfAllRecords: number,
- results: Array<{ id: string; revision: string }>,
- ): Promise<{ records: Array<{ id: string; revision: string }> }> {
+ results: UpdateRecordsForResponse,
+ ): Promise<{
+ records: UpdateRecordsForResponse;
+ }> {
const CHUNK_LENGTH =
this.bulkRequestClient.REQUESTS_LENGTH_LIMIT * UPDATE_RECORDS_LIMIT;
- const { app, records } = params;
+ const { app, upsert, records } = params;
const recordsChunk = records.slice(0, CHUNK_LENGTH);
if (recordsChunk.length === 0) {
return { records: results };
@@ -453,6 +463,7 @@ export class RecordClient extends BaseClient {
try {
newResults = await this.updateAllRecordsWithBulkRequest({
app,
+ upsert,
records: recordsChunk,
});
} catch (e: any) {
@@ -467,6 +478,7 @@ export class RecordClient extends BaseClient {
return this.updateAllRecordsRecursive(
{
app,
+ upsert,
records: records.slice(CHUNK_LENGTH),
},
numOfAllRecords,
@@ -476,6 +488,7 @@ export class RecordClient extends BaseClient {
private async updateAllRecordsWithBulkRequest(params: {
app: AppID;
+ upsert?: boolean;
records: Array<
| { id: RecordID; record?: RecordForParameter; revision?: Revision }
| {
@@ -484,7 +497,7 @@ export class RecordClient extends BaseClient {
revision?: Revision;
}
>;
- }): Promise> {
+ }): Promise {
const separatedRecords = this.separateArrayRecursive(
UPDATE_RECORDS_LIMIT,
[],
@@ -495,11 +508,14 @@ export class RecordClient extends BaseClient {
endpointName: "records" as const,
payload: {
app: params.app,
+ upsert: params.upsert,
records,
},
}));
const results = (await this.bulkRequestClient.send({ requests }))
- .results as Array<{ records: Array<{ id: string; revision: string }> }>;
+ .results as Array<{
+ records: UpdateRecordsForResponse;
+ }>;
return results
.map((result) => result.records)
.reduce((acc, records) => {
diff --git a/packages/rest-api-client/src/client/__tests__/record/AllRecords.test.ts b/packages/rest-api-client/src/client/__tests__/record/AllRecords.test.ts
index 70d207f0b7..c7121a02f7 100644
--- a/packages/rest-api-client/src/client/__tests__/record/AllRecords.test.ts
+++ b/packages/rest-api-client/src/client/__tests__/record/AllRecords.test.ts
@@ -620,6 +620,7 @@ describe("AllRecordsTest", () => {
describe("updateAllRecords", () => {
const params = {
app: APP_ID,
+ upsert: false,
records: Array.from({ length: 3000 }, (_, index) => index + 1).map(
(value) => ({
id: value,
diff --git a/packages/rest-api-client/src/client/__tests__/record/Record.test.ts b/packages/rest-api-client/src/client/__tests__/record/Record.test.ts
index 4b18f7b725..936e281d7d 100644
--- a/packages/rest-api-client/src/client/__tests__/record/Record.test.ts
+++ b/packages/rest-api-client/src/client/__tests__/record/Record.test.ts
@@ -298,6 +298,7 @@ describe("RecordTest", () => {
describe("updateRecords", () => {
const params = {
app: APP_ID,
+ upsert: false,
records: [{ id: RECORD_ID, record, revision: 5 }],
};
beforeEach(async () => {
diff --git a/packages/rest-api-client/src/client/types/record/index.ts b/packages/rest-api-client/src/client/types/record/index.ts
index 0b95da5edc..961e7c7527 100644
--- a/packages/rest-api-client/src/client/types/record/index.ts
+++ b/packages/rest-api-client/src/client/types/record/index.ts
@@ -26,3 +26,8 @@ export type Comment = {
};
export type CommentID = string | number;
+
+export type UpdateRecordsForResponse = Array<
+ | { id: string; revision: string }
+ | { id: string; operation: "INSERT" | "UPDATE"; revision: string }
+>;