Shopping Content API では、バッチ リクエストに複数のエントリを含めることができます。各エントリは、リソースで定義されている任意のメソッド(挿入、更新、削除、カスタム)にすることができます。
Merchant API にはカスタム バッチ メソッドはありません。代わりに、個々のリクエストの並列実行を設定できます。
クライアント ライブラリを使用する
クライアント ライブラリを使用している場合は、この Shopping Content API コードを検討してください。
ProductsCustomBatchResponse batchResponse =
content.products().custombatch(batchRequest).execute();
Merchant API の同等のコードは次のように記述します。
List<ApiFuture<ProductInput>> futures;
for (InsertProductInputRequest request : requests) {
futures.add(productInputsServiceClient.insertProductInputCallable().futureCall(request));
}
List<ProductInput> responses;
for (ApiFuture<ProductInput> future : futures) {
responses.add(future.get());
}
クライアント ライブラリなし
クライアント ライブラリを使用していない場合は、複数のリクエストを一括で送信するで説明されているようにバッチ処理を行います。
たとえば、Content API for Shopping リクエストを次のように置き換えます。
POST https://shoppingcontent.googleapis.com/content/v2.1/products/batch
{
"entries": [
{
"method": "insert",
"product": { … }
} … ]
}
バッチ リクエストを作成する例をご覧ください。