Text Suggestions API は、Product Studio API の生成 AI ツールを活用して、商品タイトルと説明文を生成、最適化します。この API を使用すると、顧客エンゲージメントとコンバージョンを改善し、商品情報の管理と更新のプロセスを効率化できます。Product Studio API の機能は、小売業のパフォーマンスの最適化に役立ちます。
API を使用して生成できるもの
Text Suggestions API は、次のことに役立ちます。
- 商品画像や商品属性に基づく商品タイトルと説明文の候補。
- 商品の SEO 最適化タイトル
- 商品のカスタム形式のタイトル
- 商品フィードからの商品説明
説明文のトーンを指定して、すべての商品リスティングで一貫性を維持することもできます。
クイックスタート
The GenerateProductTextSuggestions
メソッドを使用すると、商品情報を使用して商品タイトルと説明文を生成または最適化できます。
API は次のものを受け入れます。
- 商品属性(JSON ディクショナリ): 商品属性を含む JSON オブジェクト(例:
{"title": "White Tee", "brand": "MyBrand", "size": "XL"}) - 商品画像: 商品画像を指す URI(例:
{"uri": "https://my-store.com/img/1.png"}) - タイトルの書式設定オプション: タイトル生成をカスタマイズするためのパラメータ。
以下が含まれます。
attribute_separator: 属性間の区切り文字を指定します。target_language: 出力言語を設定します。attribute_order: 生成されたタイトルの属性の順序を定義します。
- データのラベル付けの例: 説明からタイトルを生成する 方法の例をご覧ください。
- ワークフロー ID(
output_spec.workflow_id):workflow_idフィールドによってoutput_specオブジェクト内のテキスト生成のタイプが決まります:title: 商品タイトルを生成または最適化します。description: 商品説明を生成または最適化します。tide: 商品タイトルと説明文の両方を生成または最適化します。
例
以下に、API を使用して、さまざまな商品データの入力からタイトル、説明文、またはその両方を生成または最適化する例を示します。よくあるエラーと問題とその解決策も紹介します。
最適化されたタイトルの生成
この例では、最適なタイトルを生成する方法を示します。
リクエスト
リクエストの本文には、タイトルの最適化に使用する商品情報が含まれます。 リクエストの構造の例を次に示します。
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Nike Mens shoes",
"description": "Give strength to your step with the Nike Air Zoom Pegasus 38 shoe for Men with shoe size 12. Ensuring the fit is loved by the runners. This shoes comes in Blue color.",
"brand": "Nike"
}
},
"output_spec": {
"workflow_id": "title"
}
}
レスポンス
次のようなレスポンスが返されます。
{
"title": {
"text": "Nike Mens shoes Air Zoom Pegasus 38 Running Shoes, Blue, Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"color": "Blue",
"size": "12",
"product": "Running shoes",
"model": "Air Zoom Pegasus 38"
},
}
}
}
画像のみからタイトルを生成する
この例では、商品画像を提供して最適なタイトルを生成する方法を示します。
リクエスト
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
},
"output_spec": {
"workflow_id": "title",
"attribute_separator": "-"
}
}
レスポンス
{
"title": {
"text": "Rustic Ceramic & Leather Leaves Necklace"
},
"metadata": {
"metadata": {
"attributes": {
"material": "Rustic Ceramic & Leather",
"pattern": "Leaves",
"product": "Necklace"
},
}
}
}
説明からタイトルを生成する
この例では、商品説明を提供して最適なタイトルを生成する方法を示します。
リクエスト
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"description": "selling size 12 nike dunks. oh they are red by the way!"
}
},
"output_spec": {
"workflow_id": "title",
}
}
レスポンス
{
"title": {
"text": "Nike Dunks Red Size 12"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Nike",
"color": "Red",
"size": "12",
"product": "Dunks"
},
}
}
}
タイトルと説明文(カスタムの例を含む)からタイトルを最適化する
この例では、AI に識別させる商品属性と、出力の属性の順序を明示的にラベル付けします。
リクエスト
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
"brand": "Luxe Beauty"
}
},
"output_spec": {
"workflow_id": "title"
}
"title_examples": [
{
"product_info": {
"title": "Lash Paradise Volumizing & Lengthening Mascara - Waterproof - Blackest Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Lash Paradise",
"mascara_type": "Volumizing & Lengthening",
"colour": "Blackest Black",
"waterproof": "Waterproof",
}
},
{
"product_info": {
"title": "Hypnose Drama Instant Full Body Volume Mascara - Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Hypnose",
"sub_brand": "Drama",
"mascara_type": "Full Body Volume",
"colour": "Black",
"eye_lash_type": "All lash types"
}
}
]
}
レスポンス
{
"title": {
"text": "Luxe Beauty Dark Brown Volumizing & Lengthening Mascara"
},
"metadata": {
"metadata": {
"attributes": {
"brand": "Luxe Beauty",
"colour": "Dark Brown",
"mascara_type": "Volumizing & Lengthening",
"product": "Mascara"
},
}
}
}
タイトルから説明文を生成する
この例では、商品タイトルを提供し、対応する商品説明を生成するよう API にリクエストする方法を示します。
リクエスト
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Rustic Ceramic & Leather Leaves Necklace",
}
},
"output_spec": {
"workflow_id": "description"
}
}
レスポンス
{
"description": {
"text": "Rustic Ceramic & Leather Leaves Necklace is a beautiful necklace made from high-quality ceramic and leather. It features a unique design that is sure to turn heads.
"
},
}
商品属性(ブランドや色など)からタイトルと説明文を生成する
この例では、商品属性を提供して最適な商品タイトルと説明文を生成する方法を示します。
リクエスト
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"brand": "Mr. Beast",
"color": "purple",
},
"product_image":{
"uri": "https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500"
}
},
"output_spec": {
"workflow_id": "description"
}
}
レスポンス
{
"title": {
"text": "Pajamas - Mr. Beast | Purple"
},
"description": {
"text": "Slip into the ultimate comfort and style with these Mr. Beast pajamas in a vibrant shade of purple. Crafted from the softest materials, these pajamas will envelop you in a cozy embrace, ensuring a restful night's sleep. The shorts feature a relaxed fit, allowing for easy movement, while the top boasts a classic design with a comfortable neckline. Whether you're lounging at home or drifting off to dreamland, these Mr. Beast pajamas are the perfect choice for a peaceful and stylish slumber."
},
}
ターゲット言語のサポート
このフィールドでは、API レスポンスで生成される説明文の言語を指定します。target_language は output_spec パラメータの一部として追加できます。
{
"output_spec": {
"target_language": "language"
}
}
値の例:
"korean" (Korean)
"english" (English)
"spanish" (Spanish)
"french" (French)
リクエストの例
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Granos de café negro",
"description": "Los granos de café negro en California",
"brand": "Parfums de Paris",
"scent": "Floral",
},
"product_image":{
"uri": "https://mrbeast.store/cdn/shop/files/0015dlv_0000_327.jpg?v=1702754475&width=500"
}
},
"output_spec": {
"workflow_id": "description",
"target_language": "japanese",
"attribute_order": ["scent", "product"],
"tone": "playful",
}
}
レスポンス
{
"description": {
"text": "カリフォルニアの黒いコーヒー豆は、あなたの鼻をくすぐる、甘く、フローラルな香りです。この香りは、コーヒー豆の豊かな香りと、ジャスミンとバラの繊細な花の香りをブレンドしたものです。カリフォルニアの黒いコーヒー豆は、あなたの家を居心地の良いカフェに変え、あなたをリラックスした気分にさせてくれるでしょう。この香りは、コーヒー好きにも、フローラルな香り好きにも最適です。カリフォルニアの黒いコーヒー豆で、あなたの家を幸せな香りで満たしましょう!."
},
}
説明文生成のトーンのパーソナライズ
ブランドを確立し、オンライン ショップを他社と差別化するために、生成された説明文のトーンをパーソナライズできます。Text API には次の 2 つのオプションがあります。
- 定義済みのトーンの選択: トーンのリストから選択して、新しい説明文を生成できます。リストには、次のトーンスタイルが含まれています。
- デフォルト: シンプルでわかりやすく、上品。
- 遊び心のある: 陽気で、ポジティブな言葉遣い、ユーモア(ジョーク、駄洒落)、誇張(皮肉、嫌味、絵文字は使用しない)。
- フォーマル: 標準的な英語、正しい文法、完全な文、スラングや短縮形は使用しない。
- 説得力のある: 論理的で簡潔、読者を説得するための議論主導型。
- 会話調: 親しみやすく、わかりやすい日常的な言葉遣い。
- ブランド固有のトーン: ブランドのトーンで既存の説明文やその他のテキスト アセットを提供できます。生成 AI モデルは、テキストのトーンを分析し、次の要素に基づいて「ライティング スタイル記述子」を生成します。
- フォーマル度 (フォーマル、カジュアルなど)
- 読み上げの詳細設定 (簡潔、非常に詳細など)
- トーン (プロフェッショナル、有益、ポジティブ、説得力があるなど)
- 文の構造 (接続詞が少ないシンプルな文など)
- 最もよく使用される単語やフレーズ
クライアント ライブラリ
リクエストを送信するには、クライアント ライブラリを使用することをおすすめします。クライアント ライブラリは、Maven プロジェクトにインストールできます。
コードサンプル
認証方法を選択し、次の手順に沿ってコードサンプルを設定します。 テキスト候補の生成に使用できるサンプルを次に示します。
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductTextSuggestionsRequest;
import com.google.shopping.merchant.productstudio.v1alpha.GenerateProductTextSuggestionsResponse;
import com.google.shopping.merchant.productstudio.v1alpha.OutputSpec;
import com.google.shopping.merchant.productstudio.v1alpha.ProductInfo;
import com.google.shopping.merchant.productstudio.v1alpha.TextSuggestionsServiceClient;
import com.google.shopping.merchant.productstudio.v1alpha.TextSuggestionsServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to generate product text suggestions. */
public class GenerateProductTextSuggestionsSample {
private static String getName(String accountId) {
return String.format("accounts/%s", accountId);
}
public static void generateProductTextSuggestions(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
TextSuggestionsServiceSettings textSuggestionsServiceSettings =
TextSuggestionsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String name = getName(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (TextSuggestionsServiceClient textSuggestionsServiceClient =
TextSuggestionsServiceClient.create(textSuggestionsServiceSettings)) {
ProductInfo productInfo =
ProductInfo.newBuilder()
.putProductAttributes("title", "Mens shirt")
.putProductAttributes("description", "A blue shirt for men in size S")
.build();
OutputSpec outputSpec = OutputSpec.newBuilder().setWorkflowId("title").build();
GenerateProductTextSuggestionsRequest request =
GenerateProductTextSuggestionsRequest.newBuilder()
.setName(name)
.setProductInfo(productInfo)
.setOutputSpec(outputSpec)
.build();
System.out.println("Sending GenerateProductTextSuggestions request: " + name);
GenerateProductTextSuggestionsResponse response =
textSuggestionsServiceClient.generateProductTextSuggestions(request);
System.out.println("Generated product text suggestions response below:");
System.out.println(response);
} catch (Exception e) {
System.out.println("An error has occured: ");
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
generateProductTextSuggestions(config);
}
}
Python
"""A module to generate product text suggestions."""
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_productstudio_v1alpha import GenerateProductTextSuggestionsRequest
from google.shopping.merchant_productstudio_v1alpha import OutputSpec
from google.shopping.merchant_productstudio_v1alpha import ProductInfo
from google.shopping.merchant_productstudio_v1alpha import TextSuggestionsServiceClient
# Fetches the Merchant Center account ID from the configuration file.
# This ID is used to construct the 'name' for the API request.
_ACCOUNT_ID = configuration.Configuration().read_merchant_info()
# The parent resource name for the GenerateProductTextSuggestionsRequest.
# Format: "accounts/{account}"
_PARENT_RESOURCE_NAME = f"accounts/{_ACCOUNT_ID}"
def generate_product_text_suggestions_sample():
"""Generates product text suggestions for a given product."""
# Gets OAuth Credentials.
credentials = generate_user_credentials.main()
# Creates a client for the TextSuggestionsService.
client = TextSuggestionsServiceClient(credentials=credentials)
# Defines the product information for which suggestions are needed.
# This includes attributes like title and description.
product_info = ProductInfo(
product_attributes={
"title": "Mens shirt",
"description": "A blue shirt for men in size S",
}
)
# Defines the output specification.
# The 'workflow_id' specifies the type of text suggestion, e.g., "title".
output_spec = OutputSpec(workflow_id="title")
# Creates the request object for generating product text suggestions.
# It includes the parent resource name, product information, and output
# specification.
request = GenerateProductTextSuggestionsRequest(
name=_PARENT_RESOURCE_NAME,
product_info=product_info,
output_spec=output_spec,
)
# Sends the request to the API.
print(
f"Sending GenerateProductTextSuggestions request: {_PARENT_RESOURCE_NAME}"
)
try:
response = client.generate_product_text_suggestions(request=request)
# Prints the generated suggestions.
print("Generated product text suggestions response below:")
print(response)
except RuntimeError as e:
# Catches and prints any errors that occur during the API call.
print("An error has occured: ")
print(e)
if __name__ == "__main__":
generate_product_text_suggestions_sample()
よくあるエラーと問題
以下に、よくある落とし穴とその解決策をいくつか示します。
テキスト候補を生成するには商品情報が必要です
次のエラー メッセージが表示された場合は、
Error message:
"error": {
"code": 400,
"message": "[product_info] Product info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
リクエストの本文に product_info を追加し、product_attributes または product_image
の少なくとも 1 つに正しい値を入力します。
たとえば、これを投稿するとエラーが発生します。
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"output_spec": {
"workflow_id": "title"
}
}
テキスト候補を生成するには、product_info の少なくとも 1 つのフィールドが必要です
このエラー
{
"error": {
"code": 400,
"message": "[product_info.product_attributes] At least one field of product_info is required to generate text suggestions.",
"status": "INVALID_ARGUMENT",
...
}
は、リクエストの本文に少なくとも 1 つの product_info フィールドを含める必要があることを示しています。
たとえば、これを投稿するとエラーが発生します。
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
},
"output_spec": {
"workflow_id": "title"
}
}
代わりに、次のようなものを使用します。
"product_info": {
"product_attributes": {
"description": "Selling size 12 Nike dunks. Oh they are red by the way!"
}
}
または
"product_info": {
"product_image":{
"uri": "https://cdn.shopify.com/s/files/1/0653/5879/0892/products/1672082339438_550x825.jpg?v=1672082415"
}
}
各 title_example で(何か)が必要です
次の 4 つの例のようなエラー
{
"error": {
"code": 400,
"message": "[title_examples.product_info] At least one field of product_info is required in each title_example.",
"status": "INVALID_ARGUMENT",
...
}
または
{
...
"message": "[title_examples.category] Category is required in each title_example.",
...
}
または
{
...
"message": "[title_examples.title_format] Title format is required in each title_example.",
...
}
または
{
...
"message": "[title_examples.final_product_info] At least one field of final_product_info is required in each title_example.",
...
}
は、必須のサブフィールドが入力されていないことを示しています。
たとえば、次のリクエストではエラーが発生します。
POST
https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"description": "selling size 12 nike dunks. oh they are red by the way!"
}
},
"output_spec": {
"workflow_id": "title"
},
"title_examples": []
}
この問題を解決するには、リクエストで指定された title_example ごとに、次のすべてのサブフィールドに入力します。
product_infocategorytitle_formatfinal_product_info
有効な例を次に示します。
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
}
},
"output_spec": {
"workflow_id": "title"
},
"title_examples": [
{
"product_info": {
"title": "Lash Paradise Volumizing & Lengthening Mascara - Waterproof - Blackest Black",
"colour": "Black"
},
"title_format": "product",
"category": "mascara",
"final_product_info": {
"product": "Mascara",
"brand": "Lash Paradise",
"mascara_type": "Volumizing & Lengthening",
"colour": "Blackest Black",
"waterproof": "Waterproof",
}
}
]
}
サポートされていない workflow_id
このタイプのエラー
{
"error": {
"code": 400,
"message": "[\u003ceye3 title='/ProductStudioTextGenerationService.GenerateProductText, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR; ... ;Unsupported workflow_id: attributes. Supported workflows are: [\"title\", \"description\", \"tide\"];AppErrorCode=3;StartTimeMs=1740696804045;unknown;ResFormat=uncompressed;ServerTimeSec=0.005976589;LogBytes=256;Non-FailFast;EffSecLevel=none;ReqFormat=uncompressed;ReqID=4d1786f59faa3ea7;GlobalID=0;Server=[2002:a05:6e16:618:b0:2c2:7cfc:bebd]:14001] Invalid value",
"status": "INVALID_ARGUMENT",
...
}
は、次のようなリクエストで発生します。
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
},
"output_spec": {
"workflow_id": "attributes"
}
}
リクエストでは workflow_id が「attributes」に設定されていますが、このフィールドでは次のいずれか 1 つの値のみがサポートされています。
- title: 商品タイトルを生成または最適化します。
- description: 商品説明を生成または最適化します。
- tide: 商品タイトルと説明文の両方を生成または最適化します。
サポートされていないトーン
次のような「Unsupported tone」エラー
{
"error": {
"code": 400,
"message": "[\u003ceye3 title='/ProductStudioTextGenerationService.GenerateProductText, INVALID_ARGUMENT'/\u003e APPLICATION_ERROR; ... ; Unsupported tone: 'asdf'. Supported tones are: [\"default\", \"playful\", \"formal\", \"persuasive\", \"conversational\"];AppErrorCode=3;StartTimeMs=1740697325058;unknown;ResFormat=uncompressed;ServerTimeSec=7.45346E-4;LogBytes=256;Non-FailFast;EffSecLevel=none;ReqFormat=uncompressed;ReqID=f7d9bbbc73a1d342;GlobalID=0;Server=[2002:a05:6918:3486:b0:2bc:ccd4:79e6]:14001] Invalid value",
"status": "INVALID_ARGUMENT",
...
}
は、次のようなリクエストで発生します。
POST https://merchantapi.googleapis.com/productstudio/v1alpha/accounts/{ACCOUNT_ID}:generateProductTextSuggestions
{
"product_info": {
"product_attributes": {
"title": "Volumizing & Lengthening Mascara - Dark Brown",
"description": "This high-impact mascara delivers both voluptuous volume and dramatic length without clumping or smudging.",
},
"output_spec": {
"workflow_id": "description"
"tone": "cheerful"
}
}
tone が「cheerful」に設定されていますが、このフィールドでは次のいずれか 1 つの値のみがサポートされています。
- default: シンプルでわかりやすく、上品。
- playful: 陽気で、ポジティブな言葉遣い、ユーモア(ジョーク、駄洒落)、 誇張(皮肉、嫌味、絵文字は使用しない)。
- フォーマル: 標準的な英語、正しい文法、完全な文、スラング や短縮形は使用しない。
- persuasive: 論理的で簡潔、 読者を説得するための議論主導型。
- 会話的: 親しみやすく、わかりやすい日常的な言葉遣い。