सीएसएस प्रॉडक्ट अपडेट करना

UpdateCssProductInput का इस्तेमाल करके, किसी मौजूदा सीएसएस प्रॉडक्ट को अपडेट करें. इसके लिए, प्रॉडक्ट cssProductInput.name और JSON बॉडी की जानकारी दें. इसमें वह डेटा शामिल होना चाहिए जिसे आपको प्रॉडक्ट के लिए अपडेट करना है.

ध्यान दें: यह तरीका, सिर्फ़ अपडेट करने के अनुरोध में दिए गए एट्रिब्यूट को अपडेट करता है. जवाब में वही एट्रिब्यूट होते हैं जो अनुरोध में होते हैं. साथ ही, अपडेट लागू होने के बाद 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 की सूची में कोई फ़ील्ड दिया गया है, लेकिन अनुरोध के मुख्य हिस्से में नहीं दिया गया है, तो प्रॉडक्ट रिसॉर्स से उस फ़ील्ड को मिटा दिया जाएगा. हालांकि, ऐसा तब ही किया जाएगा, जब वह फ़ील्ड मौजूद हो.

दिए गए उदाहरण में, फ़ील्ड title की वैल्यू हटाने के लिए updateMask का इस्तेमाल किया जाएगा.

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

ACCOUNT_ID: खाते का यूनीक आइडेंटिफ़ायर, जैसे कि 123.

CSS_PRODUCT_ID: सीएसएस प्रॉडक्ट आईडी, जैसे कि de~DE~B019G4.

title फ़ील्ड को मिटाने के लिए, उसे अनुरोध के मुख्य हिस्से से हटा दें. आपके पास बिना मुख्य हिस्से या खाली मुख्य हिस्से के भी अनुरोध भेजने का विकल्प है. updateMask में मौजूद फ़ील्ड में कोई बदलाव नहीं होगा.