rocket
Scopri l'
API Merchant, il successore ufficiale dell'API Content for Shopping.
add_alert
Nota: l'API Content for Shopping verrà ritirata il 18 agosto 2026.
Inviare richieste
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa guida presuppone che tu abbia letto la nostra guida Guida introduttiva e che tu abbia configurato il tuo account per effettuare richieste autorizzate.
Una volta configurato tutto, puoi inviare richieste alla Google Content API for Shopping. I seguenti esempi di codice
mostrano come inviare alcune semplici richieste:
- Crea un prodotto.
- Ottieni un elenco di prodotti.
- Recupera un prodotto specifico dall'elenco.
- Aggiorna il prezzo di un prodotto.
Per un elenco completo dei metodi, consulta la
documentazione di riferimento.
Per saperne di più, consulta la pagina Best practice, che
spiega come utilizzare al meglio l'API.
Questa pagina spiega anche perché sono consigliate le richieste batch.
Se hai problemi con l'API Content, controlla la
dashboard dello stato di Merchant Center per interruzioni e la
pagina Assistenza.
Creare un prodotto
Puoi trovare tutti i dettagli di tutti gli attributi che un prodotto può avere nella
specifica dei feed di prodotto.
Per creare un prodotto
, utilizza il seguente codice:
Protocollo
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);
Ottenere un elenco di prodotti
Per ottenere un elenco di prodotti, utilizza il seguente codice:
Protocollo
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);
}
Recuperare un prodotto specifico
Per recuperare un prodotto specifico dall'elenco, utilizza il seguente codice:
Protocollo
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());
Aggiornare la disponibilità dei prodotti online
Puoi utilizzare i
feed supplementari nella risorsa Prodotti per aggiornare i dati di prodotto online con il seguente
codice:
Protocollo
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);
Aggiornare la disponibilità dei prodotti locali
Puoi utilizzare il
servizio inventario locale per aggiornare i dati dei prodotti locali con il seguente codice:
Protocollo
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);
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-29 UTC.
[null,null,["Ultimo aggiornamento 2025-08-29 UTC."],[[["\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```"]]