Skip to content

Conversation

@nameless-mc
Copy link
Contributor

@nameless-mc nameless-mc commented Nov 12, 2025

Why

kintone API の 2025年1月12日のアップデートで、Update Records API に UPSERT mode
が追加されました。この機能により、指定されたレコードが存在する場合は更新、存在しない場合は新規作成を一度のAPI呼び出しで実行できるようになります。Java
Clientでもこの新機能をサポートする必要があります。

ref: https://cybozu.dev/ja/kintone/news/api-updates/2025-01/

What

REST APIとしてはUpdate Records APIのオプション(upsertパラメーター)として実装されていますが、リクエスト・レスポンスともにパラメーターが追加されているため、JavaクライアントとしてはupdateRecordsとは独立したインターフェースとして実装しました。これにより、既存のupdateRecordsメソッドへの破壊的変更を防止しています。

  • UpsertRecordsRequest クラスを新規作成(upsert = true が常に設定される)
  • UpsertRecordsResponseBody クラスを新規作成
  • レコード操作のタイプを表す RecordOperationType enum を新規作成(UPDATE / INSERT)
  • Upsert Records API のレスポンスを表す RecordUpsertResult クラスを新規作成(id、revision、operation を含む)
  • KintoneApi.UPSERT_RECORDS を追加
  • RecordClient.upsertRecords(long, List) メソッドを追加
  • RecordClient.upsertRecords(UpsertRecordsRequest) メソッドを追加

How to test

Checklist

  • Read CONTRIBUTING.md at the repository.
  • Updated documentation if it is required.
  • Added/updated tests if it is required. (or tested manually)

@nameless-mc nameless-mc self-assigned this Nov 12, 2025
Copilot AI review requested due to automatic review settings November 12, 2025 07:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the UPSERT mode feature introduced in the kintone API update (January 12, 2025) for the Update Records API. The UPSERT mode allows updating existing records or creating new ones in a single API call.

Key changes:

  • Added upsert field to UpdateRecordsRequest for enabling UPSERT mode
  • Introduced RecordOperationType enum (UPDATE/INSERT) and RecordUpdateResult class to handle operation type information
  • Changed the return type of RecordClient.updateRecords() from List<RecordRevision> to List<RecordUpdateResult> (breaking change)

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
UpdateRecordsRequest.java Added optional upsert field to enable UPSERT mode
RecordOperationType.java New enum defining UPDATE and INSERT operation types
RecordUpdateResult.java New class containing record ID, revision, and operation type
UpdateRecordsResponseBody.java Changed to use RecordUpdateResult instead of RecordRevision
RecordClient.java Updated return type of updateRecords() method to use RecordUpdateResult
RecordClientTest.java Updated test to verify the new RecordUpdateResult return type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @return a list of record update results. See {@link RecordUpdateResult}
*/
public List<RecordRevision> updateRecords(long app, List<RecordForUpdate> records) {
public List<RecordUpdateResult> updateRecords(long app, List<RecordForUpdate> records) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upsertRecords(app, records)があってもよさそう

    public List<RecordUpdateResult> upsertRecords(long app, List<RecordForUpdate> records) {
        UpdateRecordsRequest req = new UpdateRecordsRequest();
        req.setApp(app);
        req.setUpsert(true);
        req.setRecords(records);
        return updateRecords(req).getRecords();
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f2e22da で対応


import lombok.Value;

/** A value that contains the record ID, revision, and operation, returned by Update Records API. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b7a495f で対応

@nameless-mc nameless-mc force-pushed the feat/add-upsert-mode-to-update-records branch from b7a495f to 293aa73 Compare November 27, 2025 05:44
@nameless-mc nameless-mc changed the title feat!: add upsert mode to update records feat: add upsert mode to update records Nov 27, 2025
@nameless-mc nameless-mc merged commit cf14896 into master Dec 2, 2025
2 checks passed
@nameless-mc nameless-mc deleted the feat/add-upsert-mode-to-update-records branch December 2, 2025 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants