Insert CSS Product
Stay organized with collections
Save and categorize content based on your preferences.
Use this method to insert a product or update an existing product.
If the product already exists, this method works as an upsert method. This
method updates all the given data but deletes the data that isn't provided
again. So, you must send all the field values again. For example, if you only
include headlineOfferPrice
and rawProvidedId
attributes, then all other
values are deleted.
cURL
curl --location 'https://css.googleapis.com/v1/accounts/1234567/cssProductInputs:insert' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_TOKEN>' \
--data '{"rawProvidedId":"test_css_product_input","feedLabel":"FR","contentLanguage":"fr","attributes":{"title":"item-title-1","headlineOfferLink":"headline-offer.com","customLabel0":"cla0","headlineOfferCondition":"new","description":"CSSProductDescription","numberOfOffers":"123","cppLink":"cpp_link.com","brand":"test brand","googleProductCategory":"Media>Books","gtin":"3614030018942","imageLink":"http://example.com/0.jpg","headlineOfferPrice":{"currency_code":"EUR","amount_micros":"2000000"},"certifications":[{"code":"12","authority":"EuropeanCommission","name":"EPREL"}],"productHighlights":["test highlight"],"productDetails":[{"sectionName":"test section","attributeName":"test attribute","attributeValue":"test value"}]}}'
Java
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package shopping.css.samples.v1.cssproducts;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.css.v1.CssProductInput;
import com.google.shopping.css.v1.CssProductInputsServiceClient;
import com.google.shopping.css.v1.CssProductInputsServiceSettings;
import com.google.shopping.css.v1.InsertCssProductInputRequest;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to insert a CSS Product for a given Account */
public class InsertCssProductInput {
private static String getParent(String domainId) {
return String.format("accounts/%s", domainId);
}
private static String getName(String domainId, String productId) {
return String.format("accounts/%s/cssProductInputs/%s", domainId, productId);
}
public static void insertCssProductInput(Config config, long feedId, String rawProvidedId)
throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
CssProductInputsServiceSettings cssProductInputsServiceSettings =
CssProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
String parent = getParent(config.getDomainId().toString());
try (CssProductInputsServiceClient cssProductInputsServiceClient =
CssProductInputsServiceClient.create(cssProductInputsServiceSettings)) {
InsertCssProductInputRequest request =
InsertCssProductInputRequest.newBuilder()
.setParent(parent)
.setCssProductInput(
CssProductInput.newBuilder()
.setRawProvidedId(rawProvidedId)
.setFeedLabel("DE")
.setContentLanguage("de")
.setAttributes(
com.google.shopping.css.v1.Attributes.newBuilder()
.setTitle("Attribute Title")
.setHeadlineOfferLink("abc.com")
.setHeadlineOfferCondition("New")
.setDescription("CSS Product description 0")
.setNumberOfOffers(123)
.setCppLink("cpp_link.com")
.setBrand("CSS brand")
.setGoogleProductCategory("Media > Books")
.setGtin("3614030018941")
.setHeadlineOfferPrice(
com.google.shopping.type.Price.newBuilder().build())
.build())
.build())
.setFeedId(feedId)
.build();
System.out.println("Sending InsertCssProductInput request");
CssProductInput response = cssProductInputsServiceClient.insertCssProductInput(request);
System.out.println("Inserted CssProduct Name below");
System.out.println(response.getName());
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
final Config config = Config.load();
// The ID uniquely identifying each feed
final long feedId = 0;
// Create a thread pool to insert multiple CSS Products in parallel
ExecutorService threadPool = Executors.newCachedThreadPool();
for (int i = 0; i < 100; i++) {
// The raw ID identifying each product
final String rawProvidedId = "rawProvidedId" + i;
threadPool.execute(
() -> {
try {
insertCssProductInput(config, feedId, rawProvidedId);
} catch (Exception e) {
System.out.println(e);
}
});
}
}
}
JSON
{
"rawProvidedId": "test_css_product_input",
"feedLabel": "FR",
"contentLanguage": "fr",
"attributes": {
"title": "item-title-1",
"headlineOfferLink": "headline-offer.com",
"customLabel0": "cla0",
"headlineOfferCondition": "new",
"description": "CSS Product Description",
"numberOfOffers": "123",
"cppLink": "cpp_link.com",
"brand": "test brand",
"googleProductCategory": "Media > Books",
"gtin": "3614030018942",
"imageLink": "http://example.com/0.jpg",
"headlineOfferPrice": {
"currency_code": "EUR",
"amount_micros": "2000000"
},
"certifications": [{
"code": "12",
"authority": "European Commission",
"name": "EPREL"
}],
"productHighlights": [
"test highlight"
],
"productDetails": [{
"sectionName": "test section",
"attributeName": "test attribute",
"attributeValue": "test value"
}]
}
}
Other attributes
For a full list of attributes, see CSS Product data
specification.
Most of the product related attributes from the
rich product merchant API
apply here as well.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-25 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-25 UTC."],[[["\u003cp\u003eThis method allows you to insert a new product or update an existing one, acting as an upsert operation.\u003c/p\u003e\n"],["\u003cp\u003eWhen updating, all product data must be provided again, as omitting fields will result in their deletion.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the CSS Product data specification for a complete list of available product attributes.\u003c/p\u003e\n"],["\u003cp\u003eMany product attributes are shared with the rich product merchant API.\u003c/p\u003e\n"]]],[],null,["# Insert CSS Product\n\nUse this method to insert a product or update an existing product.\n\nIf the product already exists, this method works as an *upsert* method. This\nmethod updates all the given data but deletes the data that isn't provided\nagain. So, you must send all the field values again. For example, if you only\ninclude `headlineOfferPrice` and `rawProvidedId` attributes, then all other\nvalues are deleted. \n\n### cURL\n\n curl --location 'https://css.googleapis.com/v1/accounts/1234567/cssProductInputs:insert' \\\n --header 'Content-Type: application/json' \\\n --header 'Authorization: Bearer \u003cAPI_TOKEN\u003e' \\\n --data '{\"rawProvidedId\":\"test_css_product_input\",\"feedLabel\":\"FR\",\"contentLanguage\":\"fr\",\"attributes\":{\"title\":\"item-title-1\",\"headlineOfferLink\":\"headline-offer.com\",\"customLabel0\":\"cla0\",\"headlineOfferCondition\":\"new\",\"description\":\"CSSProductDescription\",\"numberOfOffers\":\"123\",\"cppLink\":\"cpp_link.com\",\"brand\":\"test brand\",\"googleProductCategory\":\"Media\u003eBooks\",\"gtin\":\"3614030018942\",\"imageLink\":\"http://example.com/0.jpg\",\"headlineOfferPrice\":{\"currency_code\":\"EUR\",\"amount_micros\":\"2000000\"},\"certifications\":[{\"code\":\"12\",\"authority\":\"EuropeanCommission\",\"name\":\"EPREL\"}],\"productHighlights\":[\"test highlight\"],\"productDetails\":[{\"sectionName\":\"test section\",\"attributeName\":\"test attribute\",\"attributeValue\":\"test value\"}]}}'\n\n### Java\n\n // Copyright 2023 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.css.samples.v1.cssproducts;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.css.v1.CssProductInput;\n import com.google.shopping.css.v1.CssProductInputsServiceClient;\n import com.google.shopping.css.v1.CssProductInputsServiceSettings;\n import com.google.shopping.css.v1.InsertCssProductInputRequest;\n import java.util.concurrent.ExecutorService;\n import java.util.concurrent.Executors;\n import shopping.css.samples.utils.Authenticator;\n import shopping.css.samples.utils.Config;\n\n /** This class demonstrates how to insert a CSS Product for a given Account */\n public class InsertCssProductInput {\n\n private static String getParent(String domainId) {\n return String.format(\"accounts/%s\", domainId);\n }\n\n private static String getName(String domainId, String productId) {\n return String.format(\"accounts/%s/cssProductInputs/%s\", domainId, productId);\n }\n\n public static void insertCssProductInput(Config config, long feedId, String rawProvidedId)\n throws Exception {\n GoogleCredentials credential = new Authenticator().authenticate();\n\n CssProductInputsServiceSettings cssProductInputsServiceSettings =\n CssProductInputsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n String parent = getParent(config.getDomainId().toString());\n\n try (CssProductInputsServiceClient cssProductInputsServiceClient =\n CssProductInputsServiceClient.create(cssProductInputsServiceSettings)) {\n\n InsertCssProductInputRequest request =\n InsertCssProductInputRequest.newBuilder()\n .setParent(parent)\n .setCssProductInput(\n CssProductInput.newBuilder()\n .setRawProvidedId(rawProvidedId)\n .setFeedLabel(\"DE\")\n .setContentLanguage(\"de\")\n .setAttributes(\n com.google.shopping.css.v1.Attributes.newBuilder()\n .setTitle(\"Attribute Title\")\n .setHeadlineOfferLink(\"abc.com\")\n .setHeadlineOfferCondition(\"New\")\n .setDescription(\"CSS Product description 0\")\n .setNumberOfOffers(123)\n .setCppLink(\"cpp_link.com\")\n .setBrand(\"CSS brand\")\n .setGoogleProductCategory(\"Media \u003e Books\")\n .setGtin(\"3614030018941\")\n .setHeadlineOfferPrice(\n com.google.shopping.type.Price.newBuilder().build())\n .build())\n .build())\n .setFeedId(feedId)\n .build();\n\n System.out.println(\"Sending InsertCssProductInput request\");\n CssProductInput response = cssProductInputsServiceClient.insertCssProductInput(request);\n System.out.println(\"Inserted CssProduct Name below\");\n System.out.println(response.getName());\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n final Config config = Config.load();\n // The ID uniquely identifying each feed\n final long feedId = 0;\n\n // Create a thread pool to insert multiple CSS Products in parallel\n ExecutorService threadPool = Executors.newCachedThreadPool();\n for (int i = 0; i \u003c 100; i++) {\n // The raw ID identifying each product\n final String rawProvidedId = \"rawProvidedId\" + i;\n threadPool.execute(\n () -\u003e {\n try {\n insertCssProductInput(config, feedId, rawProvidedId);\n } catch (Exception e) {\n System.out.println(e);\n }\n });\n }\n }\n } \n https://github.com/googleads/comparison-shopping-service-api-samples/blob/2f511c3ca413bdbd497f89ae7468b3191dafaa6d/java/src/main/java/shopping/css/samples/v1/cssproducts/InsertCssProductInput.java\n\n### JSON\n\n {\n \"rawProvidedId\": \"test_css_product_input\",\n \"feedLabel\": \"FR\",\n \"contentLanguage\": \"fr\",\n \"attributes\": {\n \"title\": \"item-title-1\",\n \"headlineOfferLink\": \"headline-offer.com\",\n \"customLabel0\": \"cla0\",\n \"headlineOfferCondition\": \"new\",\n \"description\": \"CSS Product Description\",\n \"numberOfOffers\": \"123\",\n \"cppLink\": \"cpp_link.com\",\n \"brand\": \"test brand\",\n \"googleProductCategory\": \"Media \u003e Books\",\n \"gtin\": \"3614030018942\",\n \"imageLink\": \"http://example.com/0.jpg\",\n \"headlineOfferPrice\": {\n \"currency_code\": \"EUR\",\n \"amount_micros\": \"2000000\"\n },\n \"certifications\": [{\n \"code\": \"12\",\n \"authority\": \"European Commission\",\n \"name\": \"EPREL\"\n }],\n \"productHighlights\": [\n \"test highlight\"\n ],\n \"productDetails\": [{\n \"sectionName\": \"test section\",\n \"attributeName\": \"test attribute\",\n \"attributeValue\": \"test value\"\n }]\n }\n }\n\nOther attributes\n----------------\n\nFor a full list of attributes, see [CSS Product data\nspecification](//support.google.com/css-center/answer/13583244).\n\nMost of the product related attributes from the\n[rich product merchant API](/shopping-content/guides/products/rich-product-data)\napply here as well."]]