CSS পণ্য আপডেট করুন

বিদ্যমান কোনো একক CSS প্রোডাক্ট আপডেট করতে UpdateCssProductInput মেথডটি ব্যবহার করুন। এর জন্য cssProductInput.name এবং প্রোডাক্টটির জন্য যে ডেটা আপডেট করতে চান তা সম্বলিত একটি JSON বডি উল্লেখ করুন।

Note : This method only updates the attributes provided in the update request. The response contains the same attributes as the request and does not reflect the full CssProductInput state after the update is applied. You shouldn't rely on the response to determine the final state of the CssProductInput .

PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}

To add or modify an attribute in a product, specify the field with the new value in the JSON body. The example shown will update the title and headline offer link of an existing product name 123/cssProductInputs/de~DE~B019G4 with the attribute value provided in the request body, leaving all other fields untouched.

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 রিকোয়েস্টের মাধ্যমে আপডেট করা যায়। যদি আপনি নেস্টেড ফিল্ডগুলো আপডেট করতে চান, তবে আপনাকে সম্পূর্ণ শীর্ষ-স্তরের অবজেক্টটি প্রদান করতে হবে।

The example shown will update the top-level headlineOfferPrice object, including the nested fields of an existing product, with the product data provided in the request body, leaving all other fields untouched.

PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}
{
  "attributes": {
    "headlineOfferPrice": {
      "amountMicros": "17.99",
      "currencyCode": "USD"
    }
  }
}

অনুরোধের মূল অংশে অন্তর্ভুক্ত অন্যান্য ফিল্ডে কোনো পরিবর্তন না করে শুধুমাত্র নির্দিষ্ট কিছু ফিল্ড আপডেট করার জন্য, আপনি একটি updateMask উল্লেখ করতে পারেন। এই কোয়েরি স্ট্রিং প্যারামিটারটি হবে আপনার পরিবর্তন করতে হবে এমন ফিল্ডগুলোর একটি কমা-দ্বারা-বিভক্ত তালিকা। যখন আপনি নিশ্চিত করতে চান যে শুধুমাত্র নামযুক্ত ফিল্ডগুলোই আপডেট করা হবে, তখন একটি updateMask কার্যকর হয়। updateMask উল্লেখ না করা মানে হলো অনুরোধের সমস্ত ফিল্ডকে আপডেটের জন্য চিহ্নিত করা, যেমনটি উদাহরণে দেখানো হয়েছে। তবে, যদি স্পষ্টভাবে একটি updateMask প্রদান করা না হয়, তাহলে বিদ্যমান অ্যাট্রিবিউটগুলো মুছে ফেলা সম্ভব নয়।

The example shown will update only the title of the existing item with the respective product data provided in the request body, leaving all other fields including the headline offer link untouched.

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` রিসোর্স থেকে সেই ফিল্ডটি মুছে ফেলা হবে, যদি রিসোর্সটি বিদ্যমান থাকে।

প্রদর্শিত উদাহরণটিতে title ফিল্ডের মান মুছে ফেলার জন্য `updateMask` ব্যবহার করা হবে।

PATCH https://css.googleapis.com/v1/accounts/{ACCOUNT_ID}/cssProductInputs/{CSS_PRODUCT_ID}?updateMask=title

ACCOUNT_ID : অ্যাকাউন্টের অনন্য শনাক্তকারী, যেমন, 123

CSS_PRODUCT_ID : CSS প্রোডাক্ট আইডি, উদাহরণস্বরূপ, de~DE~B019G4

title ফিল্ডটি মুছে ফেলার জন্য, এটিকে রিকোয়েস্ট বডি থেকে বাদ দিন। আপনি বডি ছাড়া বা একটি খালি বডি দিয়েও রিকোয়েস্টটি পাঠাতে পারেন। যে ফিল্ডগুলো updateMask-এ নেই, সেগুলো অপরিবর্তিত থাকবে।