rocket
隆重推出
Merchant API
- Content API for Shopping 的官方後繼產品。
update
掌握最新資訊
瞭解 Merchant API 的新功能、錯誤修正和更新。
add_alert
注意:Content API for Shopping 將於 2026 年 8 月 18 日停用。
提出要求
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本指南假設您已完成入門指南,並已設定好發出授權要求的環境。
完成所有設定後,即可向 Google Content API for Shopping 傳送要求。下列程式碼範例示範如何傳送幾項簡單要求:
- 建立產品。
- 取得產品清單。
- 從清單中擷取特定產品。
- 更新產品價格。
如需完整的方法清單,請參閱
參考說明文件。
詳情請參閱「最佳做法」頁面,瞭解如何以最佳方式使用 API。本頁面也會說明為何建議使用批次要求。
如果 Content API 發生問題,請查看
Merchant Center 狀態資訊主頁是否有服務中斷情形,以及支援頁面。
建立產品
如要瞭解產品可擁有的所有屬性,請參閱產品動態饋給規格。如要建立產品
,請使用下列程式碼:
通訊協定
POST /content/v2.1/YOUR_MERCHANT_ID/products
{
"offerId": "book123",
"title": "A Tale of Two Cities",
"description": "A classic novel about the French Revolution",
"link": "http://my-book-shop.com/tale-of-two-cities.html",
"imageLink": "http://my-book-shop.com/tale-of-two-cities.jpg",
"contentLanguage": "en",
"targetCountry": "GB",
"feedLabel": "GB",
"channel": "online",
"availability": "in stock",
"condition": "new",
"googleProductCategory": "Media > Books",
"gtin": "9780007350896",
"price": {
"value": "2.50",
"currency": "GBP"
},
"shipping": [{
"country": "GB",
"service": "Standard shipping",
"price": {
"value": "0.99",
"currency": "GBP"
}
}],
"shippingWeight": {
"value": "200",
"unit": "grams"
}
}
Java
Product product = new Product();
product.setOfferId("book123");
product.setTitle("A Tale of Two Cities");
product.setDescription("A classic novel about the French Revolution");
product.setLink("http://my-book-shop.com/tale-of-two-cities.html");
product.setImageLink("http://my-book-shop.com/tale-of-two-cities.jpg");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
product.setAvailability("in stock");
product.setCondition("new");
product.setGoogleProductCategory("Media > Books");
product.setGtin("9780007350896");
Price price = new Price();
price.setValue("2.50");
price.setCurrency("GBP");
product.setPrice(price);
Price shippingPrice = new Price();
shippingPrice.setValue("0.99");
shippingPrice.setCurrency("GBP");
ProductShipping shipping = new ProductShipping();
shipping.setPrice(shippingPrice);
shipping.setCountry("GB");
shipping.setService("Standard shipping");
ArrayList shippingList = new ArrayList();
shippingList.add(shipping);
product.setShipping(shippingList);
Product result = service.products().insert(merchantId, product).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
$product->setOfferId('book123');
$product->setTitle('A Tale of Two Cities');
$product->setDescription('A classic novel about the French Revolution');
$product->setLink('http://my-book-shop.com/tale-of-two-cities.html');
$product->setImageLink('http://my-book-shop.com/tale-of-two-cities.jpg');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
$product->setAvailability('in stock');
$product->setCondition('new');
$product->setGoogleProductCategory('Media > Books');
$product->setGtin('9780007350896');
$price = new Google_Service_ShoppingContent_Price();
$price->setValue('2.50');
$price->setCurrency('GBP');
$shipping_price = new Google_Service_ShoppingContent_Price();
$shipping_price->setValue('0.99');
$shipping_price->setCurrency('GBP');
$shipping = new Google_Service_ShoppingContent_ProductShipping();
$shipping->setPrice($shipping_price);
$shipping->setCountry('GB');
$shipping->setService('Standard shipping');
$shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
$shipping_weight->setValue(200);
$shipping_weight->setUnit('grams');
$product->setPrice($price);
$product->setShipping(array($shipping));
$product->setShippingWeight($shipping_weight);
$result = $service->products->insert($merchant_id, $product);
取得產品清單
如要取得產品清單,請使用下列程式碼:
通訊協定
GET /content/v2.1/YOUR_MERCHANT_ID/products
Java
List productsList = service.products().list(merchantId);
ProductsListResponse page = productsList.execute();
while ((page.getResources() != null) && !page.getResources().isEmpty()) {
for (Product product : page.getResources()) {
System.out.printf("%s %s%n", product.getId(), product.getTitle());
}
if (page.getNextPageToken() == null) {
break;
}
productsList.setPageToken(page.getNextPageToken());
page = productsList.execute();
}
PHP
$products = $service->products->listProducts($merchantId);
$parameters = array();
while (!empty($products->getResources()) {
foreach ($products->getResources() as $product) {
printf("%s %s\n", $product->getId(), $product->getTitle());
}
if (!empty($products->getNextPageToken()) {
break;
}
$parameters['pageToken'] = $products->nextPageToken;
$products = $service->products->listProducts($merchantId, $parameters);
}
擷取特定產品
如要從清單中擷取特定產品,請使用下列程式碼:
通訊協定
GET /content/v2.1/YOUR_MERCHANT_ID/products/online:en:GB:book123
Java
Product product = service.products()
.get(merchantId, "online:en:GB:book123")
.execute();
System.out.printf("%s %s\n", product.getId(), product.getTitle());
PHP
$product = $service->products->get($merchant_id, 'online:en:GB:book123');
printf("%s %s\n", $product->getId(), $product->getTitle());
更新線上產品供應情形
你可以在產品資源中使用
補充動態饋給,透過下列程式碼更新線上產品資料:
通訊協定
POST /content/v2.1/YOUR_MERCHANT_ID/products?YOUR_SUPPLEMENTAL_FEED_ID
{
"offerId": "book123",
"contentLanguage": "en",
"targetCountry": "GB",
"feedLabel": "GB",
"channel": "online",
"availability": "out of stock"
}
Java
Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
// Optional Fields to Update
product.setAvailability("out of stock");
// Your unique supplemental feedId
feedId=123456789
Product result = service.products().insert(merchantId, product, feedId).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
// Optional Fields to Update
$product->setAvailability('out of stock');
// Your unique supplemental feedId
$feedId=123456789
$result = $service->products->insert($merchant_id, $product, $feedId);
更新店面產品供應情形
你可以使用
店面商品目錄服務,透過下列程式碼更新店面產品資料:
通訊協定
POST /content/v2.1/YOUR_MERCHANT_ID/localinventory/online/products/online:en:GB:book123
{
"availability": "out of stock"
}
Java
Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
// Optional Fields to Update
product.setAvailability("out of stock");
Product result = service.localinventory().insert(merchantId, product).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
// Optional Fields to Update
$product->setAvailability('out of stock');
$result = $service->localinventory->insert($merchant_id, $product);
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eThe Merchant API is the new version of the Content API for Shopping and represents the future of product data integration with Google.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides code samples to manage products, including creating, retrieving, listing, and updating them via the API.\u003c/p\u003e\n"],["\u003cp\u003eYou can find comprehensive details on product attributes in the Products Feed Specification and best practices for using the API in the provided links.\u003c/p\u003e\n"],["\u003cp\u003eUtilize supplemental feeds to update online product data and the Local Inventory service to manage local product information efficiently.\u003c/p\u003e\n"],["\u003cp\u003eFor support or to check for service outages, refer to the Merchant Center status dashboard and the Support page.\u003c/p\u003e\n"]]],["The Merchant API beta, a new version of the Content API for Shopping, allows users to manage product data. Key actions include creating a product with details like title, price, and shipping, retrieving a list of products, and fetching a specific product. Additionally, users can update product availability for both online and local inventory using supplemental feeds or the local inventory service. The provided code examples demonstrate these actions in Protocol, Java, and PHP.\n"],null,["# Make requests\n\nThis guide assumes you've worked through\nour [Getting Started](/shopping-content/guides/quickstart) guide and are set up to\nmake authorized requests.\n\nAfter you've set everything up, you can send requests to the Google Content API for Shopping. The following code\nsamples demonstrate how to send a few simple requests:\n\n- Create a product.\n- Get a list of products.\n- Retrieve a specific product from the list.\n- Update a product's price.\n\nFor a full list of methods, see the [reference documentation](/shopping-content/reference/rest/v2.1).\n\nFor more information, see the [Best Practices](/shopping-content/guides/best-practices) page, which\nexplains how to best use the API.\nThis page also explains why batch requests are recommended.\n\n\nIf you're having issues with the Content API, check the [Merchant Center status dashboard](//merchants.google.com/status) for outages, and the\n[Support](/shopping-content/support/contact-us) page.\n\n### Create a product\n\nYou can find full details of all the attributes that a product can have in the\n[Products Feed Specification](//support.google.com/merchants/answer/188494).\nTo [create a product](/shopping-content/reference/rest/v2.1/products/insert), use the following code: \n\nProtocol\n--------\n\n```scdoc\nPOST /content/v2.1/YOUR_MERCHANT_ID/products\n\n{\n \"offerId\": \"book123\",\n \"title\": \"A Tale of Two Cities\",\n \"description\": \"A classic novel about the French Revolution\",\n \"link\": \"http://my-book-shop.com/tale-of-two-cities.html\",\n \"imageLink\": \"http://my-book-shop.com/tale-of-two-cities.jpg\",\n \"contentLanguage\": \"en\",\n \"targetCountry\": \"GB\",\n \"feedLabel\": \"GB\",\n \"channel\": \"online\",\n \"availability\": \"in stock\",\n \"condition\": \"new\",\n \"googleProductCategory\": \"Media \u003e Books\",\n \"gtin\": \"9780007350896\",\n \"price\": {\n \"value\": \"2.50\",\n \"currency\": \"GBP\"\n },\n \"shipping\": [{\n \"country\": \"GB\",\n \"service\": \"Standard shipping\",\n \"price\": {\n \"value\": \"0.99\",\n \"currency\": \"GBP\"\n }\n }],\n \"shippingWeight\": {\n \"value\": \"200\",\n \"unit\": \"grams\"\n }\n}\n```\n\nJava\n----\n\n```java\nProduct product = new Product();\n\nproduct.setOfferId(\"book123\");\nproduct.setTitle(\"A Tale of Two Cities\");\nproduct.setDescription(\"A classic novel about the French Revolution\");\nproduct.setLink(\"http://my-book-shop.com/tale-of-two-cities.html\");\nproduct.setImageLink(\"http://my-book-shop.com/tale-of-two-cities.jpg\");\nproduct.setContentLanguage(\"en\");\nproduct.setTargetCountry(\"GB\");\nproduct.setChannel(\"online\");\nproduct.setAvailability(\"in stock\");\nproduct.setCondition(\"new\");\nproduct.setGoogleProductCategory(\"Media \u003e Books\");\nproduct.setGtin(\"9780007350896\");\n\nPrice price = new Price();\nprice.setValue(\"2.50\");\nprice.setCurrency(\"GBP\");\nproduct.setPrice(price);\n\nPrice shippingPrice = new Price();\nshippingPrice.setValue(\"0.99\");\nshippingPrice.setCurrency(\"GBP\");\n\nProductShipping shipping = new ProductShipping();\nshipping.setPrice(shippingPrice);\nshipping.setCountry(\"GB\");\nshipping.setService(\"Standard shipping\");\n\nArrayList shippingList = new ArrayList();\nshippingList.add(shipping);\nproduct.setShipping(shippingList);\n\nProduct result = service.products().insert(merchantId, product).execute();\n```\n\nPHP\n---\n\n```php\n$product = new Google_Service_ShoppingContent_Product();\n$product-\u003esetOfferId('book123');\n$product-\u003esetTitle('A Tale of Two Cities');\n$product-\u003esetDescription('A classic novel about the French Revolution');\n$product-\u003esetLink('http://my-book-shop.com/tale-of-two-cities.html');\n$product-\u003esetImageLink('http://my-book-shop.com/tale-of-two-cities.jpg');\n$product-\u003esetContentLanguage('en');\n$product-\u003esetTargetCountry('GB');\n$product-\u003esetChannel('online');\n$product-\u003esetAvailability('in stock');\n$product-\u003esetCondition('new');\n$product-\u003esetGoogleProductCategory('Media \u003e Books');\n$product-\u003esetGtin('9780007350896');\n\n$price = new Google_Service_ShoppingContent_Price();\n$price-\u003esetValue('2.50');\n$price-\u003esetCurrency('GBP');\n\n$shipping_price = new Google_Service_ShoppingContent_Price();\n$shipping_price-\u003esetValue('0.99');\n$shipping_price-\u003esetCurrency('GBP');\n\n$shipping = new Google_Service_ShoppingContent_ProductShipping();\n$shipping-\u003esetPrice($shipping_price);\n$shipping-\u003esetCountry('GB');\n$shipping-\u003esetService('Standard shipping');\n\n$shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();\n$shipping_weight-\u003esetValue(200);\n$shipping_weight-\u003esetUnit('grams');\n\n$product-\u003esetPrice($price);\n$product-\u003esetShipping(array($shipping));\n$product-\u003esetShippingWeight($shipping_weight);\n\n$result = $service-\u003eproducts-\u003einsert($merchant_id, $product);\n```\n\n### Get a list of products\n\nTo [get a list of\nproducts](/shopping-content/reference/rest/v2.1/products/list), use the following code: \n\nProtocol\n--------\n\n```scdoc\nGET /content/v2.1/YOUR_MERCHANT_ID/products\n```\n\nJava\n----\n\n```text\nList productsList = service.products().list(merchantId);\n\nProductsListResponse page = productsList.execute();\nwhile ((page.getResources() != null) && !page.getResources().isEmpty()) {\n for (Product product : page.getResources()) {\n System.out.printf(\"%s %s%n\", product.getId(), product.getTitle());\n }\n\n if (page.getNextPageToken() == null) {\n break;\n }\n\n productsList.setPageToken(page.getNextPageToken());\n page = productsList.execute();\n}\n```\n\nPHP\n---\n\n```ecl\n$products = $service-\u003eproducts-\u003elistProducts($merchantId);\n$parameters = array();\nwhile (!empty($products-\u003egetResources()) {\n foreach ($products-\u003egetResources() as $product) {\n printf(\"%s %s\\n\", $product-\u003egetId(), $product-\u003egetTitle());\n }\n if (!empty($products-\u003egetNextPageToken()) {\n break;\n }\n $parameters['pageToken'] = $products-\u003enextPageToken;\n $products = $service-\u003eproducts-\u003elistProducts($merchantId, $parameters);\n}\n```\n\n### Retrieve a specific product\n\nTo [retrieve a specific\nproduct from the list](/shopping-content/reference/rest/v2.1/products/get), use the following code: \n\nProtocol\n--------\n\n```scdoc\nGET /content/v2.1/YOUR_MERCHANT_ID/products/online:en:GB:book123\n```\n\nJava\n----\n\n```css+lasso\nProduct product = service.products()\n .get(merchantId, \"online:en:GB:book123\")\n .execute();\nSystem.out.printf(\"%s %s\\n\", product.getId(), product.getTitle());\n```\n\nPHP\n---\n\n```css+lasso\n$product = $service-\u003eproducts-\u003eget($merchant_id, 'online:en:GB:book123');\nprintf(\"%s %s\\n\", $product-\u003egetId(), $product-\u003egetTitle());\n```\n\n### Update online product availability\n\nYou can use [Supplemental Feeds](/shopping-content/guides/products/supplemental-feeds) in the Products resource to update online product data with the following\ncode: \n\nProtocol\n--------\n\n```scdoc\nPOST /content/v2.1/YOUR_MERCHANT_ID/products?YOUR_SUPPLEMENTAL_FEED_ID\n\n{\n \"offerId\": \"book123\",\n \"contentLanguage\": \"en\",\n \"targetCountry\": \"GB\",\n \"feedLabel\": \"GB\",\n \"channel\": \"online\",\n \"availability\": \"out of stock\"\n}\n```\n\nJava\n----\n\n```text\nProduct product = new Product();\n// Mandatory Fields\nproduct.setOfferId(\"book123\");\nproduct.setContentLanguage(\"en\");\nproduct.setTargetCountry(\"GB\");\nproduct.setChannel(\"online\");\n\n// Optional Fields to Update\nproduct.setAvailability(\"out of stock\");\n\n// Your unique supplemental feedId\nfeedId=123456789\n\nProduct result = service.products().insert(merchantId, product, feedId).execute();\n```\n\nPHP\n---\n\n```ecl\n$product = new Google_Service_ShoppingContent_Product();\n// Mandatory Fields\n$product-\u003esetOfferId('book123');\n$product-\u003esetContentLanguage('en');\n$product-\u003esetTargetCountry('GB');\n$product-\u003esetChannel('online');\n\n// Optional Fields to Update\n$product-\u003esetAvailability('out of stock');\n\n// Your unique supplemental feedId\n$feedId=123456789\n\n$result = $service-\u003eproducts-\u003einsert($merchant_id, $product, $feedId);\n```\n\n### Update local product availability\n\nYou can use the [Local Inventory Service](/shopping-content/reference/rest/v2.1/localinventory) to update local product data with the following code: \n\nProtocol\n--------\n\n```scdoc\nPOST /content/v2.1/YOUR_MERCHANT_ID/localinventory/online/products/online:en:GB:book123\n\n{\n \"availability\": \"out of stock\"\n}\n```\n\nJava\n----\n\n```text\nProduct product = new Product();\n// Mandatory Fields\nproduct.setOfferId(\"book123\");\nproduct.setContentLanguage(\"en\");\nproduct.setTargetCountry(\"GB\");\nproduct.setChannel(\"online\");\n\n// Optional Fields to Update\nproduct.setAvailability(\"out of stock\");\n\nProduct result = service.localinventory().insert(merchantId, product).execute();\n```\n\nPHP\n---\n\n```ecl\n$product = new Google_Service_ShoppingContent_Product();\n// Mandatory Fields\n$product-\u003esetOfferId('book123');\n$product-\u003esetContentLanguage('en');\n$product-\u003esetTargetCountry('GB');\n$product-\u003esetChannel('online');\n\n// Optional Fields to Update\n$product-\u003esetAvailability('out of stock');\n\n$result = $service-\u003elocalinventory-\u003einsert($merchant_id, $product);\n```"]]