このページでは、プログラマティックに商品をアップロードして管理する方法について説明します。Merchant Products API を使用すると、データソースに商品を挿入または更新したり、アカウントから商品を取得したり、データソースから商品を削除したりできます。
Merchant Products API には 2 つのリソースがあります。
productInputs
は、商品の入力部分を表します。products
は、入力パーツから作成された処理済みプロダクトを表します。
productInputs
は、メイン データソースまたは補助データソースにアップロードされるかどうかに応じて、メインまたは補助にすることができます。各 product
は、1 つのプライマリ productInput
と任意の数の補足 productInputs
から構成されます。
Merchant Products API を使用して、オンライン ストアまたはローカル ストアのカタログを作成できます。これらのカタログに登録された商品は、複数のショッピング デスティネーションに表示できます。productInputs
リソースは、Merchant Center アカウントを作成して最初のデータソースを設定し、API を使用して最初の商品セットをアップロードする準備ができたら使用できます。
販売者は PrimaryProductDataSource というファイルを使用した商品のアップロードが可能ですが、Merchant API を使用して商品を作成、削除することにはいくつかの利点があります。これらのメリットには、レスポンス時間の短縮や、大規模なファイルを管理することなく商品をリアルタイムで更新できる機能などがあります。API 呼び出しによって行われた商品の変更がショッピング データベースに反映されるまでには、最大で数時間かかることがあります。
前提条件
データソースがない場合は、Merchant Data Sources API または Merchant Center を使用してデータソースを作成します。
Merchant Center の UI または API を使用して作成したデータソースがすでにある場合は、Merchant Products API を使用して商品を追加できます。Content API for Shopping を使用して商品を追加している場合は、移行ガイドで Merchant Products API の使用を開始する方法をご覧ください。
ショッピング広告と無料リスティングのポリシーに準拠する責任は販売者に帰属します。ショッピング広告は、これらのポリシーを適用し、これらのポリシーに違反するコンテンツや行為が見つかった場合は適切に対応する権利を有します。
リソース
products
リソースを使用すると、ショッピング データベースから商品情報を取得できます。
productInput
リソースは、商品に対して送信する入力データを表します。また、バッチモードで商品情報を 1 つずつ、または複数まとめて更新または削除できるメソッドも用意されています。productInput
リソースには、次のフィールドが必要です。
channel
: 商品のチャネル。offerId
: 商品の一意の識別子。contentLanguage
: 商品の 2 文字の ISO 639-1 言語コード。feedLabel
: 商品を分類して識別できるラベル。使用できる文字は 20 文字までで、A-Z
、0-9
、ハイフン、アンダースコアがサポートされています。フィードラベルにスペースを含めることはできません。詳細については、フィードラベルの使用をご覧ください。
アカウントに商品入力をアップロードする
商品入力をアカウントにアップロードするには、accounts.productInputs.insert
メソッドを使用します。メイン データソースまたは補助データソースの一意の識別子を渡す必要があります。
次のサンプル リクエストは、accounts.productInputs.insert
メソッドを使用して商品の入力を販売者アカウントにアップロードする方法を示しています。このリクエストでは、送料と地域、製造日やサイズなどのカスタム属性を設定します。
POST https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs:insert?dataSource={DATASOURCE}
{
"name": "{PRODUCT_TITLE}",
"versionNumber": {VERSION_NUMBER},
"contentLanguage": "{CONTENT_LANGUAGE}",
"feedLabel": "{FEED_LABEL}",
"offerId": "{OFFER_ID}",
"channel": "ONLINE",
"attributes": {
"availability": "in stock",
"imageLink": "{IMAGE_LINK}",
"link": "{PRODUCT_LINK}",
"brand": "{BRAND_NAME}",
"price": {
"currencyCode": "{CURRENCY_CODE}",
"amountMicros": {PRICE}
},
"color": "red",
"productWeight": {
"value": 320,
"unit": "g"
},
"adult": false,
"shipping": [
{
"country": "GB",
"price": {
"amountMicros": {SHIPPING_COST},
"currencyCode": "{CURRENCY_CODE_SHIPPING}"
},
"postalCode": "{SHIPPING_POSTALCODE}",
"service": "",
"region": "{SHIPPING_REGION}",
"maxHandlingTime": "{MAX_HANDLING_TIME}",
"minHandlingTime": "{MIN_HANDLING_TIME}",
"maxTransitTime": "{MAX_TRANSIT_TIME}",
"minTransitTime": "{MIN_TRANSIT_TIME}"
}
],
"gender": "Female"
},
"customAttributes": [
{
"name": "size",
"value": "Large"
},
{
"name": "Date of Manufacturing",
"value": "2024-05-05"
}
]
}
次のように置き換えます。
- {ACCOUNT_ID}: Merchant Center アカウントの一意の識別子。
- {DATASOURCE}: データソースの一意の識別子。
accounts/
{ACCOUNT_ID}/dataSources/
{DATASOURCE_ID} の形式にする必要があります。 - {PRODUCT_TITLE}: プロダクトの名前。
- {VERSION_NUMBER}: プロダクトのバージョン番号。省略可。
- {CONTENT_LANGUAGE}: 商品の 2 文字の ISO 639-1 言語コード。必須。
- {FEED_LABEL}: 商品を分類して識別できるラベル。使用できる文字は最大 20 文字で、サポートされている文字は
A-Z
、0-9
、ハイフン、アンダースコアです。フィードラベルにスペースを含めることはできません。 - {OFFER_ID}: 商品の一意の識別子。必須。
- {IMAGE_LINK}: ウェブサイト上の商品画像へのリンク。省略可。
- {PRODUCT_LINK}: ウェブサイトの商品へのリンク。省略可。
- {CURRENCY_CODE}: ISO 4217 に準拠した 3 文字の略語を使用した価格の通貨。省略可。
- {PRICE}: 商品の価格(マイクロ単位の数値)。省略可。
- {SHIPPING_COST}: 固定の送料(数値)。省略可。
- {SHIPPING_POSTALCODE}: 送料が適用される郵便番号の範囲。省略可。
- {MAX_HANDLING_TIME}: 注文を受けてから発送されるまでの最長発送準備時間(営業日数)。省略可。
- {MIN_HANDLING_TIME}: 注文を受けてから発送されるまでの最短発送準備時間(営業日数)。値 0 は、注文が受領された当日に配達されることを意味します。省略可。
- {MAX_TRANSIT_TIME}: 注文が発送されてから配達されるまでの最長お届け日数(営業日)。省略可。
- {MIN_TRANSIT_TIME}: 注文が発送されてから配達されるまでの最短お届け日数(営業日)。値 0 は、注文が配送された当日に配達されることを意味します。省略可。
リクエストが正常に実行されると、次のレスポンスが表示されます。
{
"name": "{PRODUCT_NAME}",
"product": "{PRODUCT_ID}",
"channel": "ONLINE",
"offerId": "{OFFER_ID}",
"contentLanguage": "{CONTENT_LANGUAGE}",
"feedLabel": "{FEED_LABEL}",
"versionNumber": "{VERSION_NUMBER}",
"attributes": {
"link": "{PRODUCT_LINK}",
"imageLink": "{IMAGE_LINK}",
"adult": false,
"availability": "in stock",
"brand": "{BRAND_NAME}",
"color": "red",
"gender": "Female",
"price": {
"amountMicros": "{PRICE}",
"currencyCode": "{CURRENCY_CODE}"
},
"shipping": [
{
"price": {
"amountMicros": "{SHIPPING_COST}",
"currencyCode": "{CURRENCY_CODE}"
},
"country": "{SHIPPING_COUNTRY}",
"region": "{SHIPPING_REGION}",
"postalCode": "{SHIPPING_POSTALCODE}",
"minHandlingTime": "{MIN_HANDLING_TIME}",
"maxHandlingTime": "{MAX_HANDLING_TIME}",
"minTransitTime": "{MIN_TRANSIT_TIME}",
"maxTransitTime": "{MAX_TRANSIT_TIME}"
}
],
"productWeight": {
"value": 320,
"unit": "g"
}
},
"customAttributes": [
{
"name": "Size",
"value": "Large"
},
{
"name": "Date of Manufacturing",
"value": "2024-05-05"
}
]
}
Merchant Center アカウントに商品を追加するには、次のサンプルに示すように google.shopping.merchant.accounts.v1beta.InsertProductInputSample
メソッドを使用します。
Java
public static void insertProductInput(Config config, String dataSource) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductInputsServiceSettings productInputsServiceSettings =
ProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent to identify where to insert the product.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ProductInputsServiceClient productInputsServiceClient =
ProductInputsServiceClient.create(productInputsServiceSettings)) {
// Price to be used for shipping ($33.45).
Price price = Price.newBuilder().setAmountMicros(33_450_000).setCurrencyCode("USD").build();
Shipping shipping =
Shipping.newBuilder()
.setPrice(price)
.setCountry("GB")
.setService("1st class post")
.build();
Shipping shipping2 =
Shipping.newBuilder()
.setPrice(price)
.setCountry("FR")
.setService("1st class post")
.build();
Attributes attributes =
Attributes.newBuilder()
.setTitle("A Tale of Two Cities")
.setDescription("A classic novel about the French Revolution")
.setLink("https://exampleWebsite.com/tale-of-two-cities.html")
.setImageLink("https://exampleWebsite.com/tale-of-two-cities.jpg")
.setAvailability("in stock")
.setCondition("new")
.setGoogleProductCategory("Media > Books")
.setGtin(0, "9780007350896")
.addShipping(shipping)
.addShipping(shipping2)
.build();
// The datasource can be either a primary or supplemental datasource.
InsertProductInputRequest request =
InsertProductInputRequest.newBuilder()
.setParent(parent)
// You can only insert products into datasource types of Input "API" and "FILE", and
// of Type "Primary" or "Supplemental."
// This field takes the `name` field of the datasource.
.setDataSource(dataSource)
// If this product is already owned by another datasource, when re-inserting, the
// new datasource will take ownership of the product.
.setProductInput(
ProductInput.newBuilder()
.setChannel(ChannelEnum.ONLINE)
.setContentLanguage("en")
.setFeedLabel("label")
.setOfferId("sku123")
.setAttributes(attributes)
.build())
.build();
System.out.println("Sending insert ProductInput request");
ProductInput response = productInputsServiceClient.insertProductInput(request);
System.out.println("Inserted ProductInput Name below");
// The last part of the product name will be the product ID assigned to a product by Google.
// Product ID has the format `channel~contentLanguage~feedLabel~offerId`
System.out.println(response.getName());
System.out.println("Inserted Product Name below");
System.out.println(response.getProduct());
} catch (Exception e) {
System.out.println(e);
}
}
アカウントから処理済みの商品を取得する
アカウントから処理済み商品を取得するには、accounts.products.get
メソッドを使用します。挿入後、処理された商品が表示されるまでに数分かかることがあります。
GET https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/products/{PRODUCT_NAME}
{PRODUCT_NAME} は、削除する商品入力リソースの名前に置き換えます。例: online~en~US~sku123
処理された商品のリソース名は、accounts.productInputs.insert
のレスポンスの product
フィールドから取得できます。
特定の Merchant Center アカウントの単一の商品を取得するには、次のサンプルに示すように google.shopping.merchant.accounts.v1beta.GetProductRequest
メソッドを使用します。
Java
public static void getProduct(Config config, String product) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductsServiceSettings productsServiceSettings =
ProductsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (ProductsServiceClient productsServiceClient =
ProductsServiceClient.create(productsServiceSettings)) {
// The name has the format: accounts/{account}/products/{productId}
GetProductRequest request = GetProductRequest.newBuilder().setName(product).build();
System.out.println("Sending get product request:");
Product response = productsServiceClient.getProduct(request);
System.out.println("Retrieved Product below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
アカウントから商品の入力を削除する
アカウントから商品入力を削除するには、accounts.productInputs.delete
メソッドを使用します。Merchant Products API を使用して商品を削除するには、商品が属するメインまたは補助データソースの一意の識別子を渡す必要があります。
次のリクエストは、accounts.productInputs.delete
メソッドを使用して商品入力を削除する方法を示しています。
DELETE https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/productInputs/{PRODUCT_NAME}?dataSource=accounts/{ACCOUNT_ID}/dataSources/{DATASOURCE_ID}
{PRODUCT_NAME} は、削除する商品入力リソースの名前に置き換えます。例: online~en~US~sku123
特定の Merchant Center アカウントの商品を削除するには、次のサンプルに示すように google.shopping.merchant.accounts.v1beta.DeleteProductInputRequest
メソッドを使用します。
Java
public static void deleteProductInput(Config config, String productId, String dataSource)
throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductInputsServiceSettings productInputsServiceSettings =
ProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates product name to identify product.
String name =
ProductInputName.newBuilder()
.setAccount(config.getAccountId().toString())
.setProductinput(productId)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
try (ProductInputsServiceClient productInputsServiceClient =
ProductInputsServiceClient.create(productInputsServiceSettings)) {
DeleteProductInputRequest request =
DeleteProductInputRequest.newBuilder().setName(name).setDataSource(dataSource).build();
System.out.println("Sending deleteProductInput request");
productInputsServiceClient.deleteProductInput(request); // no response returned on success
System.out.println(
"Delete successful, note that it may take a few minutes for the delete to update in"
+ " the system. If you make a products.get or products.list request before a few"
+ " minutes have passed, the old product data may be returned.");
} catch (Exception e) {
System.out.println(e);
}
}
アカウントの商品を一覧表示する
アカウントで処理された商品を一覧表示するには、次のリクエストに示すように accounts.products.list
メソッドを使用します。
GET https://merchantapi.googleapis.com/products/v1beta/accounts/{ACCOUNT_ID}/products
特定の Merchant Center アカウントの商品を一覧表示するには、次のサンプルに示すように google.shopping.merchant.accounts.v1beta.ListProductsRequest
メソッドを使用します。
Java
public static void listProducts(Config config) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
ProductsServiceSettings productsServiceSettings =
ProductsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent to identify the account from which to list all products.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (ProductsServiceClient productsServiceClient =
ProductsServiceClient.create(productsServiceSettings)) {
// The parent has the format: accounts/{account}
ListProductsRequest request = ListProductsRequest.newBuilder().setParent(parent).build();
System.out.println("Sending list products request:");
ListProductsPagedResponse response = productsServiceClient.listProducts(request);
int count = 0;
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
for (Product product : response.iterateAll()) {
System.out.println(product); // The product includes the `productStatus` field
// That shows approval and disapproval information.
count++;
}
System.out.print("The following count of products were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println("An error has occured: ");
System.out.println(e);
}
}