CSS API のベスト プラクティス
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このドキュメントでは、CSS API の使用に関するベスト プラクティスについて説明します。このページで説明する内容は、API の使用に必須ではありませんが、想定される使用方法の一部を明確にするのに役立つ可能性があります。
環境をセットアップする
開発環境を設定するには、クイックスタート ドキュメントの手順に沿って操作します。
- Google Cloud コンソールでユーザーと権限の JSON ファイルを生成する
- Google Cloud コンソールで CSS API を有効にする
- 管理者権限を持つユーザーを CSS アカウント(CSS グループまたは CSS ドメイン)に追加します。
- 正しい OAuth スコープ(
https://www.googleapis.com/auth/content
)を使用していることを確認します。
クライアント ライブラリは、ほとんどのプログラミング言語の標準リポジトリにあります。一覧については、クライアント ライブラリ ページをご覧ください。
正しい ID を使用する
正しい API エンドポイントで正しい ID を使用します。
- CSS API(
css.googleapis.com
): CSS サービス(accounts/{cssDomainId}/cssProductInputs:insert
)。
- Merchant API(
merchantapi.googleapis.com
): 標準の販売者向け商品には Merchant API を使用します。
これらを混同するとエラーが発生します。詳しくは、CSS API の概要をご覧ください。
始めるのに適した方法
次の方法でテストすることをおすすめします。
ListChildAccounts
ListChildAccounts は、すべての CSS ドメイン(CSS グループに対して呼び出された場合)または販売者(CSS ドメインに対して呼び出された場合)を一覧表示する読み取り専用の呼び出しです。そのため、すべてが正しく設定されているかどうかをテストするのに適した方法です。
商品を挿入、一覧表示、更新、削除する
API 自体が機能していることを確認したら、商品を登録してみます。忘れない raw_provided_id
を使用してください。
CSS API は並列呼び出し用に設計されています。単一のオペレーションのパフォーマンスは遅くなる可能性がありますが、同じオペレーションを並行して複数回呼び出すと、パフォーマンスは大幅に向上します。この機能を最大限に活用するには、プログラミング言語の非同期機能を使用することをおすすめします。
プログラミング言語の例:
プログラミング言語の非同期機能を見つけて使用し、複数の商品を同時に挿入します。システムが過負荷になる心配はありません。これは割り当て上限の目的です。
詳しくは、パフォーマンス ページをご覧ください。
ペイロードを検証する
一般的なエラーを回避するには、JSON ペイロードが正しくフォーマットされていることを確認します。
- 公式ドキュメントを参照する: フィールド定義、列挙型、データ型、ペイロード構造については、常に最新の CSS API リファレンスを参照してください。
- サンプル ペイロードを確認する: ペイロードを、提供されているコードサンプルと比較して、不一致を特定します。
- データ型: ドキュメントで指定されている正しいデータ型(文字列、オブジェクト、配列など)を使用していることを確認します。
- 段階的にテストする: 最小限の有効なペイロードから始めて、基本的な接続を確認し、徐々に属性を追加します。
商品を更新する
商品をアップロードすると、更新、削除、期限切れになるまでシステムに保存されます。
- 最初に使ったのと同じ
raw_provided_id
を使って InsertCssProductInput
リクエストを再度送信することで、商品全体を更新できます。現時点では、一部の属性(価格や在庫状況など)のみが変更された場合でも、完全な商品データを送信する必要があります。
- PATCH メソッド
UpdateCssProductInput
を使用して、商品の一部を更新できます。商品の名前と、更新する商品のデータを含む JSON 本文を指定します。InsertCssProductInput
では該当するすべてのフィールドを指定する必要がありますが、UpdateCssProductInput
では変更するフィールドのみを指定します。
- 同じ
raw_provided_id
を指定して DeleteCssProductInput
を呼び出すことで、商品を削除できます。
- プロダクトは、最後の更新から約 1 か月後に自動的に期限切れになります。
継続動作モード
連続オペレーション モードは次のようになります。
- 独自の内部 ID を
raw_provided_id
として使用します。
- すべての商品を定期的に(毎週など)再アップロードします。これにより、有効なアイテムの有効期限が切れるのを防ぐことができます。
- 販売者から変更されたデータを受け取ったら、すぐに個々の商品を更新します。
- 変更にすぐに対応できない場合は、変更された商品を頻繁に(1 時間ごとなど)検索し、それらの商品のみを再アップロードします。
- 販売を終了した商品については、削除呼び出しを使用するか、利用可能な販売情報の数を 0 に設定します。
- 変更のない商品を頻繁に送信しないでください。これらの呼び出しは、API 割り当ての対象になります。毎週更新すれば十分です。
ヘッドライン オファーの選択
ヘッドライン オファーは、サイトで最もお得なオファーや最も安いオファーである必要はありませんが、目立つように表示する必要があります。この機能は、上位の提案が頻繁に変わる場合に便利です。より安定した別の提案を選択できます。
このドキュメントを定期的に再確認する
この API の改善方法についてフィードバックをお寄せいただき、ありがとうございます。現在、これらの改善の一部を実装中です。CSS API の使用を簡素化する新しい機能が利用可能になったら、このページを更新します。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-13 UTC。
[null,null,["最終更新日 2025-08-13 UTC。"],[[["\u003cp\u003eThis document outlines best practices for utilizing the CSS API, including setup, testing methods, performance enhancement, product management, and headline offer selection.\u003c/p\u003e\n"],["\u003cp\u003eOptimize API performance by using asynchronous calls for parallel operations, especially for inserting multiple products simultaneously.\u003c/p\u003e\n"],["\u003cp\u003eMaintain product data by regularly re-uploading all products, updating individual products as needed, and managing product expiration or deletion.\u003c/p\u003e\n"],["\u003cp\u003eThe headline offer can be strategically chosen for prominence and stability, even if it's not the cheapest or top offer on your site.\u003c/p\u003e\n"],["\u003cp\u003eStay informed about API updates and improvements by revisiting this document periodically for new features and simplified usage guidelines.\u003c/p\u003e\n"]]],[],null,["# CSS API Best Practices\n\nThis document describes some of the best practices around using the CSS API. The\nadvice given on this page is not mandatory to use the API, but may help clarify\nsome of the intended use.\n\nSetup up your environment\n-------------------------\n\nTo setup your development environment, follow the steps given from the\n[Quickstart documentation](/comparison-shopping-services/api/guides/quickstart).\n\n- Generate a user and a permissions JSON file on the Google Cloud Console\n- Enable the CSS API in the Google Cloud Console\n- Add that user with Admin permissions to your CSS Account (CSS Group or CSS Domain)\n- Verify you are using the correct OAuth scope: `https://www.googleapis.com/auth/content`\n\nClient libraries are now in the standard repositories for most programming\nlanguage. You can find a list of them on our\n[client library](/comparison-shopping-services/api/client-libraries) page.\n\nUse correct IDs\n---------------\n\nUse the correct IDs with the correct API endpoints:\n\n- **CSS API (`css.googleapis.com`):** Use the **CSS Domain ID** when interacting with CSS products (e.g., `accounts/{cssDomainId}/cssProductInputs:insert`).\n- **Merchant API (`merchantapi.googleapis.com`):** Use the Merchant API for standard merchant products.\n\nMixing these up will lead to errors. Refer to the\n[CSS API Overview](/comparison-shopping-services/api/overview) for more details.\n\nGood methods to get started\n---------------------------\n\nWe recommend testing with the following methods:\n\n### ListChildAccounts\n\n[ListChildAccounts](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.AccountsService.ListChildAccounts)\nis a read-only call that lists all of your CSS Domains (if called for a\nCSS Group) or your Merchants (if called for a CSS Domain). It is therefore a\ngood method to test if everything is setup correctly.\n\n### Insert/List/Update/Delete a product\n\nOnce you know that the API itself works, try adding a product. Make sure you use\na `raw_provided_id` that you remember.\n\n- Insert a test product using [InsertCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.InsertCssProductInput). We have [sample code](/comparison-shopping-services/api/code-samples/cssproducts/insert-css-product-input) if you need help on which attributes to send.\n- List all of your products using [ListCssProducts](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductsService.ListCssProducts). There is a small processing delay before a product shows up after insertion, so if you don't see it, try again after a few seconds.\n- Update a single product using [UpdateCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.UpdateCssProductInput) using your `cssproductinput.name`. You need to send only the attributes required to be updated. Refer to [sample code](/comparison-shopping-services/api/code-samples/cssproducts/update-css-product-input) here.\n- Delete the test product using [DeleteCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.DeleteCssProductInput). You will need to use the `raw_provided_id`.\n\nUse Async to improve performance\n--------------------------------\n\nThe CSS API is designed for parallel calls. You will find that the performance\nof single operations can be slow, but will be much faster when calling the same\noperation multiple times in parallel. The best way to use this feature is to use\nthe async functionality of your programming language.\n\nExamples from some programming languages:\n\n- For Java, use [insertCssProductInputCallable().futureCall()](https://cloud.google.com/java/docs/reference/google-shopping-css/latest/com.google.shopping.css.v1.CssProductInputsServiceClient#com_google_shopping_css_v1_CssProductInputsServiceClient_insertCssProductInputCallable__)\n- For Python, use [CssProductInputsServiceAsyncClient](https://googleapis.dev/python/google-shopping-css/latest/css_v1/css_product_inputs_service.html)\n- For C#, use [InsertCssProductInputAsync](https://googleapis.dev/dotnet/Google.Shopping.Css.V1/latest/api/Google.Shopping.Css.V1.CssProductInputsService.CssProductInputsServiceClient.html#Google_Shopping_Css_V1_CssProductInputsService_CssProductInputsServiceClient_InsertCssProductInputAsync_Google_Shopping_Css_V1_InsertCssProductInputRequest_Grpc_Core_CallOptions_)\n\nFind and use the Async functionality of your programming language to insert\nmultiple products at the same time. You don't need to worry about overloading\nour systems - this is what the\n[quota limits](/comparison-shopping-services/api/guides/limits) are for.\n\nMore details can be found on our [performance\npage](/comparison-shopping-services/api/guides/performance).\n\nValidate Your Payloads\n----------------------\n\nTo avoid common errors, verify your JSON payloads are correctly formatted:\n\n- **Consult Official Documentation:** Always refer to the latest [CSS API reference](/comparison-shopping-services/api/reference/rest) for field definitions, enums, data types, and payload structure.\n- **Review Sample Payloads:** Compare your payloads with the provided [code samples](/comparison-shopping-services/api/code-samples) to identify discrepancies.\n- **Data Types:** Make sure you are using the correct data types (e.g., strings, objects, arrays) as specified in the documentation.\n- **Test Incrementally:** Start with minimal valid payloads to confirm basic connectivity and gradually add more attributes.\n\nUpdate a product\n----------------\n\nOnce a product is uploaded, it will stay in our system until it is either\nupdated, deleted, or expired.\n\n- You can update the full product by sending the `InsertCssProductInput` request again, using the same `raw_provided_id` you used initially. For now, you will need to send the full product data, even if only some attributes (maybe only price/availablibilty) have changed.\n- You can update parts of a product, using PATCH method `UpdateCssProductInput`, specifying product name,and a JSON body containing the data you would like to update for the product. Unlike `InsertCssProductInput`, that requires all applicable fields to be provided, `UpdateCssProductInput` only requires you to specify the fields you would like to change.\n- You can delete a product by calling `DeleteCssProductInput` with the same `raw_provided_id`.\n- Products expire automatically approximately one month after the last update.\n\nContinuous operation mode\n-------------------------\n\nA continuous operation mode could look like the following:\n\n- Use your own internal IDs as `raw_provided_id`.\n- Re-upload all products on a regular schedule, maybe weekly. This will ensure that active products don't expire.\n- Update individual products as soon as you get the changed data from your merchants.\n - If you can't react to changes immediately, find all changed products frequently (maybe hourly) and re-upload only those products.\n - For products which are no longer available, you can either use the delete call or set the number of available offers to 0.\n - Don't send us unchanged products frequently. These calls would count against your API quota. A weekly refresh is sufficient.\n\nHeadline offer selection\n------------------------\n\nThe headline offer does not necessarily need to be the top offer or the\ncheapest offer on your site, but it does need to be featured prominently. You\ncan use this for cases where your top offer is changing fast: Here you could\nselect another offer which is more stable.\n\nRe-Check this document every once in a while\n--------------------------------------------\n\nWe have received feedback on how to improve this API, and are working on making\nsome of these improvements available. This page will be updated when we have new\nfeatures available that will simplify the usage of the CSS API."]]