CSS 제품 업데이트

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"}}}'

자바

// 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 목록에는 필드가 제공되지만 요청 본문에는 제공되지 않은 경우 해당 필드가 제품 리소스에서 삭제됩니다(있는 경우).

표시된 예에서는 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에 없는 필드는 변경되지 않습니다.