제품의 속성을 추가하거나 수정하려면 JSON 본문에서 새 값으로 필드를 지정합니다. 표시된 예에서는 기존 제품 이름 123/cssProductInputs/de~DE~B019G4의 제목 및 광고 제목 제품 링크를 요청 본문에 제공된 속성 값으로 업데이트하고 다른 모든 필드는 그대로 둡니다.
// 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.packageshopping.css.samples.v1.cssproducts;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.protobuf.FieldMask;importcom.google.shopping.css.v1.CssProductInput;importcom.google.shopping.css.v1.CssProductInputsServiceClient;importcom.google.shopping.css.v1.CssProductInputsServiceSettings;importcom.google.shopping.css.v1.UpdateCssProductInputRequest;importshopping.css.samples.utils.Authenticator;importshopping.css.samples.utils.Config;/** This class demonstrates how to update a CSS Product for a given Account */publicclassUpdateCssProductInput{privatestaticStringgetName(StringdomainId,StringproductId){returnString.format("accounts/%s/cssProductInputs/%s",domainId,productId);}publicstaticvoidupdateCssProductInput(Configconfig,StringproductId)throwsException{GoogleCredentialscredential=newAuthenticator().authenticate();Stringname=getName(config.getDomainId().toString(),productId);CssProductInputsServiceSettingscssProductInputsServiceSettings=CssProductInputsServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();try(CssProductInputsServiceClientcssProductInputsServiceClient=CssProductInputsServiceClient.create(cssProductInputsServiceSettings)){// Updates the title of the CSS Product leaving the rest of the fields unchangedUpdateCssProductInputRequestrequest=UpdateCssProductInputRequest.newBuilder().setCssProductInput(CssProductInput.newBuilder().setName(name).setAttributes(com.google.shopping.css.v1.Attributes.newBuilder().setTitle("Attribute Title").setHeadlineOfferLink("abc.com").setHeadlineOfferCondition("New").setDescription("CSS Product description 0").build()).build()).setUpdateMask(FieldMask.newBuilder().addPaths("title").build()).build();System.out.println("Updating CSS Product");CssProductInputresponse=cssProductInputsServiceClient.updateCssProductInput(request);System.out.print("CSS product updated:");}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{finalConfigconfig=Config.load();// The ID uniquely identifying each product. In// the format languageCode~countryCode~rawProvidedIdfinalStringproductId="de~DE~rawProvidedId17";updateCssProductInput(config,productId);}}
요청 본문에 포함된 다른 필드를 변경하지 않고 업데이트할 특정 필드를 선택하려면 updateMask를 지정하면 됩니다. 이 쿼리 문자열 매개변수는 수정해야 하는 필드의 쉼표로 구분된 목록이어야 합니다.
updateMask는 이름이 지정된 필드만 업데이트된다고 어설션하려는 경우에 유용합니다.
updateMask를 지정하지 않으면 예와 같이 요청의 모든 필드를 업데이트하도록 표시하는 것과 같습니다. 그러나 updateMask가 명시적으로 제공되지 않으면 기존 속성을 삭제할 수 없습니다.
표시된 예에서는 요청 본문에 제공된 각 제품 데이터로 기존 상품의 title만 업데이트하고 headline offer link를 비롯한 다른 모든 필드는 그대로 둡니다.
[null,null,["최종 업데이트: 2025-07-25(UTC)"],[[["\u003cp\u003eThe \u003ccode\u003eUpdateCssProductInput\u003c/code\u003e method allows updating specific attributes of an existing CSS product by providing the \u003ccode\u003ecssProductInput.name\u003c/code\u003e and the desired changes in a JSON body.\u003c/p\u003e\n"],["\u003cp\u003eOnly the attributes specified in the update request are modified, and the response does not reflect the full updated \u003ccode\u003eCssProductInput\u003c/code\u003e state.\u003c/p\u003e\n"],["\u003cp\u003eTo modify a nested field, the entire top-level object containing that field must be provided in the request, but only top-level objects can be updated.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eupdateMask\u003c/code\u003e query parameter allows you to explicitly define which fields to update, and any field included in the \u003ccode\u003eupdateMask\u003c/code\u003e but not in the request body will be deleted.\u003c/p\u003e\n"],["\u003cp\u003eOmitting an \u003ccode\u003eupdateMask\u003c/code\u003e means all fields in the request are considered for updating, but without an \u003ccode\u003eupdateMask\u003c/code\u003e, existing attributes cannot be deleted.\u003c/p\u003e\n"]]],[],null,["# Update CSS Product\n\nUse [UpdateCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.UpdateCssProductInput)\nmethod update an existing single CSS product by specifying product\n`cssProductInput.name` and a JSON body containing the data you would like to\nupdate for the product.\n\n**Note** : This method only updates the attributes provided in the update\nrequest. The response contains the same attributes as the request and does\nnot reflect the full `CssProductInput` state after the update is applied.\nYou shouldn't rely on the response to determine the final state of the\n`CssProductInput`. \n\n PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}\n\nTo add or modify an attribute in a product, specify the field with the new\nvalue in the JSON body. The example shown will update the [title](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.Attributes.FIELDS.string.google.shopping.css.v1.Attributes.title)\nand [headline offer link](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.Attributes.FIELDS.string.google.shopping.css.v1.Attributes.headline_offer_link)\nof an existing product name `123/cssProductInputs/de~DE~B019G4` with the\nattribute value provided in the request body, leaving all other fields\nuntouched. \n\n### HTTP\n\n PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}\n {\n \"attributes\": {\n \"title\": \"new item title\",\n \"headlineOfferLink\": \"headline-offer.com\"\n }\n }\n\n### cURL\n\n curl --location --request PATCH 'https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}' \\\n --header 'Content-Type: application/json' \\\n --header 'Authorization: Bearer \u003cAPI_TOKEN\u003e' \\\n --data '{\"attributes\":{\"numberOfOffers\":\"99\",\"headlineOfferPrice\":{\"currency_code\":\"EUR\",\"amount_micros\":\"1200000\"}}}'\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.protobuf.FieldMask;\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.UpdateCssProductInputRequest;\n import shopping.css.samples.utils.Authenticator;\n import shopping.css.samples.utils.Config;\n\n /** This class demonstrates how to update a CSS Product for a given Account */\n public class UpdateCssProductInput {\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 updateCssProductInput(Config config, String productId) throws Exception {\n GoogleCredentials credential = new Authenticator().authenticate();\n String name = getName(config.getDomainId().toString(), productId);\n\n CssProductInputsServiceSettings cssProductInputsServiceSettings =\n CssProductInputsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n try (CssProductInputsServiceClient cssProductInputsServiceClient =\n CssProductInputsServiceClient.create(cssProductInputsServiceSettings)) {\n\n // Updates the title of the CSS Product leaving the rest of the fields unchanged\n UpdateCssProductInputRequest request =\n UpdateCssProductInputRequest.newBuilder()\n .setCssProductInput(\n CssProductInput.newBuilder()\n .setName(name)\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 .build())\n .build())\n .setUpdateMask(FieldMask.newBuilder().addPaths(\"title\").build())\n .build();\n\n System.out.println(\"Updating CSS Product\");\n CssProductInput response = cssProductInputsServiceClient.updateCssProductInput(request);\n System.out.print(\"CSS product updated:\");\n\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\n // The ID uniquely identifying each product. In\n // the format languageCode~countryCode~rawProvidedId\n final String productId = \"de~DE~rawProvidedId17\";\n updateCssProductInput(config, productId);\n }\n } \n https://github.com/googleads/comparison-shopping-service-api-samples/blob/2f511c3ca413bdbd497f89ae7468b3191dafaa6d/java/src/main/java/shopping/css/samples/v1/cssproducts/UpdateCssProductInput.java\n\n**Only top-level fields can be updated with `cssProductInputs.update` request.**\nIf you want to update nested fields you must provide the entire top-level\nobject.\n\nThe example shown will update the top-level `headlineOfferPrice` object,\nincluding the nested fields of an existing product, with the product data\nprovided in the request body, leaving all other fields untouched. \n\n PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}\n {\n \"attributes\": {\n \"headlineOfferPrice\": {\n \"amountMicros\": \"17.99\",\n \"currencyCode\": \"USD\"\n }\n }\n }\n\nTo select certain fields to update without making changes to the others included\nin the body of the request, you can specify an `updateMask`. This query string\nparameter should be a comma-separated list of fields you need to modify.\nAn `updateMask` is useful when you want to assert that only the named fields\nwill be updated.\nNot specifying an `updateMask` is equivalent to marking all fields in the\nrequest to be updated, as shown in the example. However, if an `updateMask` is\nnot provided explicitly, it is not possible to delete existing attributes.\n\nThe example shown will update **only** the `title`\nof the existing item with the respective product data provided in\nthe request body, leaving all other fields including the `headline offer link`\nuntouched. \n\n PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title\n {\n \"attributes\": {\n \"title\":\"item-title\",\n \"headlineOfferLink\":\"headline-offer-newer.com\"\n }\n }\n\nIf a field is provided in the updateMask list but not in the body of the\nrequest, that field will be deleted from the Product resource, if it exists.\n\nThe example shown will use updateMask to remove the value for the field `title`. \n\n PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title\n\n**ACCOUNT_ID** :\nUnique identifier for the account, for example, `123`.\n\n**CSS_PRODUCT_ID** :\nCSS product ID, for example, `de~DE~B019G4`.\n\nTo delete the `title` field, leave it out of the request body. You can also\nsend the request with no body or an empty body. Fields not in the updateMask\nwill stay unchanged.\n| **Warning:** When using `updateMask`, be careful to provide the correct value for all fields listed in the `updateMask`. If the value is not included in the body of the request, it will be the equivalent of deleting the field."]]