UpdateCssProductInput メソッドを使用して、商品 cssProductInput.name
と、商品の更新対象データを含む JSON 本文を指定し、既存の単一の CSS 商品を更新します。
注: このメソッドは、更新リクエストで指定された属性のみを更新します。レスポンスにはリクエストと同じ属性が含まれ、更新が適用された後の CssProductInput
の完全な状態は反映されません。CssProductInput
の最終状態を判断するためにレスポンスに依存しないでください。
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
商品の属性を追加または変更するには、JSON 本文で新しい値を含むフィールドを指定します。次の例では、既存の商品名 123/cssProductInputs/de~DE~B019G4
のタイトルとヘッドライン オファー リンクを、リクエスト本文で指定された属性値で更新し、他のフィールドはすべて変更しません。
HTTP
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
{
"attributes": {
"title": "new item title",
"headlineOfferLink": "headline-offer.com"
}
}
cURL
curl --location --request PATCH 'https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_TOKEN>' \
--data '{"attributes":{"numberOfOffers":"99","headlineOfferPrice":{"currency_code":"EUR","amount_micros":"1200000"}}}'
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.protobuf.FieldMask;
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.UpdateCssProductInputRequest;
import shopping.css.samples.utils.Authenticator;
import shopping.css.samples.utils.Config;
/** This class demonstrates how to update a CSS Product for a given Account */
public class UpdateCssProductInput {
private static String getName(String domainId, String productId) {
return String.format("accounts/%s/cssProductInputs/%s", domainId, productId);
}
public static void updateCssProductInput(Config config, String productId) throws Exception {
GoogleCredentials credential = new Authenticator().authenticate();
String name = getName(config.getDomainId().toString(), productId);
CssProductInputsServiceSettings cssProductInputsServiceSettings =
CssProductInputsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
try (CssProductInputsServiceClient cssProductInputsServiceClient =
CssProductInputsServiceClient.create(cssProductInputsServiceSettings)) {
// Updates the title of the CSS Product leaving the rest of the fields unchanged
UpdateCssProductInputRequest request =
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");
CssProductInput response = cssProductInputsServiceClient.updateCssProductInput(request);
System.out.print("CSS product updated:");
} 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 product. In
// the format languageCode~countryCode~rawProvidedId
final String productId = "de~DE~rawProvidedId17";
updateCssProductInput(config, productId);
}
}
cssProductInputs.update
リクエストで更新できるのは、最上位のフィールドのみです。ネストされたフィールドを更新する場合は、最上位オブジェクト全体を指定する必要があります。
この例では、リクエスト本文で指定された商品データを使用して、既存の商品のネストされたフィールドを含む最上位の headlineOfferPrice
オブジェクトを更新し、他のすべてのフィールドは変更しません。
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
{
"attributes": {
"headlineOfferPrice": {
"amountMicros": "17.99",
"currencyCode": "USD"
}
}
}
リクエスト本文に含まれる他のフィールドを変更せずに、更新する特定のフィールドを選択するには、updateMask
を指定します。このクエリ文字列パラメータは、変更する必要があるフィールドのカンマ区切りのリストにする必要があります。updateMask
は、名前付きフィールドのみが更新されることをアサートする場合に便利です。updateMask
を指定しない場合、例に示すように、リクエスト内のすべてのフィールドが更新対象としてマークされます。ただし、updateMask
が明示的に指定されていない場合、既存の属性を削除することはできません。
この例では、リクエスト本文で指定された商品データを使用して、既存のアイテムの title
のみを更新し、headline offer link
を含む他のすべてのフィールドは変更しません。
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title
{
"attributes": {
"title":"item-title",
"headlineOfferLink":"headline-offer-newer.com"
}
}
updateMask リストにフィールドが指定されていて、リクエストの本文に指定されていない場合、そのフィールドは Product リソースから削除されます(存在する場合)。
この例では、updateMask を使用してフィールド title
の値を削除します。
PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title
ACCOUNT_ID: アカウントの一意の識別子(123
など)。
CSS_PRODUCT_ID: CSS 商品 ID(de~DE~B019G4
など)。
title
フィールドを削除するには、リクエスト本文から削除します。本文なしまたは空の本文でリクエストを送信することもできます。updateMask にないフィールドは変更されません。