Content API for Shopping से Merchant API पर माइग्रेट करना

इस गाइड में, कारोबार के डेटा मैनेजमेंट के लिए, Content API for Shopping से Merchant API पर माइग्रेट करने की प्रोसेस के बारे में बताया गया है.

इस गाइड का इस्तेमाल करके, Content API for Shopping के मौजूदा इंटिग्रेशन को Merchant API पर माइग्रेट किया जा सकता है. Merchant API और इसके सब-एपीआई के बारे में ज़्यादा जानकारी के लिए, Merchant API का डिज़ाइन देखें.

शुरू करें

Merchant API का इस्तेमाल करने के लिए, अपने अनुरोध के यूआरएल को इस फ़ॉर्मैट में बदलें:

https://merchantapi.googleapis.com/{SUB_API}/{VERSION}/{RESOURCE_NAME}:{METHOD}

Merchant API का इस्तेमाल करने के लिए, आपको डेवलपर के तौर पर रजिस्टर करने के तरीके का इस्तेमाल करके, अपने Merchant Center खाते और Google Cloud प्रोजेक्ट को लिंक करना होगा. इसके लिए, यह तरीका अपनाएं:

POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/developerRegistration:registerGcp

{
  developer_email:"example-email@example.com"
}

ज़्यादा जानकारी के लिए, शुरुआती गाइड और Merchant API के बारे में जानकारी देखें.

Content API for Shopping के मुकाबले बेहतर सुविधाएं

Merchant API की मदद से, Merchant Center में वर्कफ़्लो को ऑटोमेट और स्ट्रीमलाइन किया जा सकता है. साथ ही, यह Content API for Shopping के मुकाबले बेहतर सुविधाएं देता है.

इस्तेमाल के मुख्य उदाहरण:

  • खाते के मैनेजमेंट को ऑटोमेट करना
  • प्रॉडक्ट के मैनेजमेंट को ऑटोमेट करना
  • इन्वेंट्री के मैनेजमेंट को ऑटोमेट करना
  • कस्टम रिपोर्टिंग

सुधार के मुख्य क्षेत्र:

खातों में ये बदलाव हुए हैं:

  • एपीआई कॉल के लिए, ज़्यादा से ज़्यादा pageSize वैल्यू 250 से बढ़कर 1,000 लाइनें हो गई है.
  • प्रॉडक्ट जोड़ने, प्रमोशन, प्रॉडक्ट की समीक्षाएं, और कारोबारी की समीक्षाओं में होने वाली देरी को DataSources बनाने के बाद ठीक कर दिया गया है.
  • रिपोर्टिंग sub-API में, टेबल के तहत productView clickPotentialRank की अपडेट की गई परिभाषा लॉन्च की गई है:
    • clickPotential के आधार पर प्रॉडक्ट की रैंकिंग को 1 से 1,000 के बीच की वैल्यू के हिसाब से सामान्य किया जाता है.
  • AccountIdAlias की मदद से, खाते के जटिल स्ट्रक्चर को बेहतर तरीके से मैनेज किया जा सकता है.AccountRelationship उदाहरण के लिए, मार्केटप्लेस, कारोबारी के इंटरनल आईडी (जैसे, खाते का आईडी) के बजाय, उपयोगकर्ता की ओर से तय किए गए एलियास का इस्तेमाल करते हैं.

gRPC की सुविधा

Merchant API, gRPC और REST के साथ काम करता है. Merchant API के लिए gRPC और Content API for Shopping के लिए REST का इस्तेमाल एक साथ किया जा सकता है.

Merchant API क्लाइंट लाइब्रेरी के लिए, gRPC की ज़रूरत होती है.

ज़्यादा जानकारी के लिए, gRPC की खास जानकारी देखें.

इनके साथ काम करता है

इस गाइड में, Merchant API में होने वाले सामान्य बदलावों के बारे में बताया गया है.

Merchant API को, Content API for Shopping की मौजूदा सुविधाओं के साथ काम करने के लिए डिज़ाइन किया गया है.

उदाहरण के लिए, Content API for Shopping के मौजूदा वर्शन 2.1 products इंटिग्रेशन के साथ, Merchant Inventories API का इस्तेमाल किया जा सकता है. Content API for Shopping का इस्तेमाल करके, स्थानीय स्टोर में बेचे जाने वाले किसी नए प्रॉडक्ट को अपलोड किया जा सकता है. इसके बाद, Merchant Inventories API के LocalInventory संसाधन का इस्तेमाल करके, उस प्रॉडक्ट के लिए इन-स्टोर जानकारी को मैनेज किया जा सकता है.

Content API के मुकाबले बेहतर सुविधाएं

Merchant API, Content API के मुकाबले इन मामलों में बेहतर है:

इन बदलावों के बारे में ज़्यादा जानें.

वर्शनिंग और सब-एपीआई

Merchant API में, वर्शनिंग और सब-एपीआई की अवधारणाएं शामिल हैं. इसके मॉड्यूलर डिज़ाइन से, इस्तेमाल में आसानी होती है. इसकी वजह यह है कि इससे सिर्फ़ उन सब-एपीआई पर फ़ोकस किया जा सकता है जिनकी आपको ज़रूरत है. साथ ही, आने वाले समय में नए वर्शन पर आसानी से माइग्रेट किया जा सकता है. वर्शनिंग, आपके अनुरोध के यूआरएल पर लागू होगी. यह रणनीति, Google Ads API के अनुभव जैसी ही है.

ज़्यादा मज़बूत अनुरोध

Merchant API के यूआरएल के अनुरोधों के लिए, Merchant API को कॉल करने के लिए ज़्यादा पैरामीटर की ज़रूरत होती है. इनमें संसाधन, वर्शन, नाम (आइडेंटिफ़ायर), और तरीका (नॉन-स्टैंडर्ड तरीके) शामिल हैं. इसके बारे में ज़्यादा जानने के लिए, खाते और प्रॉडक्ट के आइडेंटिफ़ायर और उदाहरण देखें.

आइडेंटिफ़ायर के लिए एआईपी के सिद्धांत

Content API for Shopping, संसाधनों की पहचान करने के लिए आईडी का इस्तेमाल करता है. जैसे, merchantId, productId. वहीं, Merchant API, एआईपी के मुताबिक, name आइडेंटिफ़ायर का इस्तेमाल करता है. एआईपी के बारे में जानने के लिए, एपीआई को बेहतर बनाने के सिद्धांत देखें.

{name} आइडेंटिफ़ायर में, संसाधन आइडेंटिफ़ायर और उसका पैरंट (या एक से ज़्यादा पैरंट) शामिल होता है. जैसे, {name} की वैल्यू accounts/{account}/products/{product} होती है

पढ़ने और लिखने के सभी कॉल, name फ़ील्ड को संसाधन आइडेंटिफ़ायर के तौर पर दिखाते हैं.

{name} में, कलेक्शन आइडेंटिफ़ायर accounts/ और products/ भी शामिल होते हैं.

Merchant API में, Merchant Center आईडी के लिए {account} और प्रॉडक्ट आइडेंटिफ़ायर के लिए {product} का इस्तेमाल किया जाता है.

उदाहरण के लिए, किसी संसाधन से name को वापस पाने के लिए, getName() तरीका लागू करें. साथ ही, कारोबारी और संसाधन आईडी से खुद name बनाने के बजाय, आउटपुट को वैरिएबल के तौर पर सेव करें.

यहां एक उदाहरण दिया गया है, जिसमें बताया गया है कि अपने कॉल में name फ़ील्ड का इस्तेमाल कैसे किया जाए:

   POST https://merchantapi.googleapis.com/inventories/v1/{PARENT}/regionalInventories:insert

टेबल में दिखाया गया है कि Content API for Shopping के products.get अनुरोध में क्या बदलाव हुए हैं:

Content API for Shopping Merchant API
GET https://shoppingcontent.googleapis.com/content/v2.1/{merchantId}/products/{productId} GET https://merchantapi.googleapis.com/products/v1/{name}

ज़्यादा जानकारी के लिए, आइडेंटिफ़ायर में हुए बदलाव देखें.

एक और उदाहरण के तौर पर, Merchant API का इस्तेमाल करके, Merchant Center आईडी 4321 से en~US~1234 आइडेंटिफ़ायर वाला प्रॉडक्ट वापस पाने का तरीका यहां दिया गया है:

    GET
    https://merchantapi.googleapis.com/products/v1/accounts/4321/products/online~en~US~1234

यहां {name} की वैल्यू accounts/4321/products/en~US~1234 है. Merchant API में, पढ़ने और लिखने के सभी कॉल के लिए, इस नए नाम फ़ील्ड को संसाधन आइडेंटिफ़ायर के तौर पर दिखाया जाता है.

**न** बनाएं.

Content API for Shopping में, कॉलन (:) प्रॉडक्ट के नाम में डीलिमिटर के तौर पर काम करता है. वहीं, Merchant API में, टिल्ड (~) यह काम करता है. Merchant API के आइडेंटिफ़ायर में, channel हिस्सा शामिल नहीं होता.

उदाहरण के लिए, Content API for Shopping में प्रॉडक्ट आईडी:

channel:contentLanguage:feedLabel:offerId.

Merchant API में यह इस तरह दिखता है:

contentLanguage~feedLabel~offerId.

चाइल्ड संसाधनों के लिए पैरंट फ़ील्ड

Merchant API में, सभी चाइल्ड संसाधनों में the parent फ़ील्ड होता है. चाइल्ड को जोड़ने के लिए, पूरे पैरंट संसाधन को पास करने के बजाय, parent फ़ील्ड का इस्तेमाल करके, संसाधन का {name} तय किया जा सकता है. आप parent फ़ील्ड का इस्तेमाल, list के साथ भी कर सकते हैं

उदाहरण के लिए, किसी प्रॉडक्ट के लिए स्थानीय इन्वेंट्री की सूची बनाने के लिए, प्रॉडक्ट का name parent फ़ील्ड में list तरीके के लिए तय करें. इस मामले में, दिया गया product संसाधनों का parent है, जो LocalInventory लौटाए गए हैं.

    GET
    https://merchantapi.googleapis.com/inventories/v1/{parent}/localInventories

प्रॉडक्ट en~US~1234' और खाते 4321 के लिए, स्थानीय इन्वेंट्री की सूची पाने का अनुरोध इस तरह दिखेगा

    GET
    https://merchantapi.googleapis.com/inventories/v1/accounts/4321/products/online~en~US~1234/localInventories</code>

पैरंट, accounts/{account}/products/{product} है. ध्यान दें कि इस मामले में the localInventories संसाधन के दो पैरंट, नाम आइडेंटिफ़ायर (accounts/ और products/) में शामिल हैं. ऐसा इसलिए है, क्योंकि खाता, प्रॉडक्ट संसाधन का पैरंट है.

सामान्य एनम

सामान्य एनम का इस्तेमाल करने से, ज़्यादा एकरूपता मिलती है.

The Destination.DestinationEnum फ़ील्ड में, उन प्लैटफ़ॉर्म के बारे में जानकारी दी जाती है जिन पर आपके संसाधन दिखाए जाते हैं. DestinationEnum में, डेस्टिनेशन टारगेटिंग के लिए उपलब्ध सभी वैल्यू की सूची होती है. साथ ही, यह सब-एपीआई में एक जैसी होती है. उदाहरण के लिए, प्रमोशन एट्रिब्यूट के लिए.

The ReportingContext.ReportingContextEnum फ़ील्ड में, उस कॉन्टेक्स्ट के बारे में जानकारी दी जाती है जिस पर आपके खाते और प्रॉडक्ट से जुड़ी समस्याएं लागू होती हैं. इस फ़ील्ड का इस्तेमाल, रिपोर्टिंग के सभी तरीकों में किया जाता है. उदाहरण के लिए, IssueSeverityPerReportingContext के लिए.

पिछले वर्शन के गेम खेलने की सुविधा

Merchant API का इस्तेमाल शुरू करने पर, Content API for Shopping का मौजूदा इंटिग्रेशन बिना किसी रुकावट के काम करता रहेगा. ज़्यादा जानकारी के लिए, नीति के मुताबिक काम करने के बारे में जानें.

अपने सब-एपीआई को Merchant API पर माइग्रेट करने के बाद, हमारा सुझाव है कि माइग्रेट किए गए सब-एपीआई के लिए सिर्फ़ Merchant API का इस्तेमाल करें.

रिमोट प्रोसीजर कॉल (gRPC) की उपलब्धता

Merchant API के साथ इंटिग्रेट करने के लिए, gRPC को नए तरीके के तौर पर इस्तेमाल करने का सुझाव दिया जाता है.

इसके ये फ़ायदे हैं:

कस्टम बैचिंग, बिल्ट-इन बैचिंग में बदल जाती है

एसिंक्रोनस कॉल का इस्तेमाल करने पर, बैचिंग ज़्यादा असरदार तरीके से काम करती है. Merchant API में बैचिंग के लिए, पैरलल कॉल का इस्तेमाल करने के बारे में ज़्यादा जानें . साथ ही, एक साथ कई अनुरोधों के लिए कोड को रीफ़ैक्टर करने का तरीका जानें .

माइग्रेशन की प्रोसेस को तेज़ करने के लिए, हम क्लाइंट लाइब्रेरीज़ का इस्तेमाल करने का सुझाव देते हैं.

Merchant API, Content API for Shopping में मौजूद customBatch तरीके के साथ काम नहीं करता. इसके बजाय, एक साथ कई अनुरोध भेजना या एसिंक्रोनस तरीके से कॉल करना देखें.

लेख पढ़ें

Java के इस सैंपल में, प्रॉडक्ट इनपुट जोड़ने का तरीका बताया गया है:

   import com.google.api.core.ApiFuture;
import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.shopping.merchant.products.v1.Availability;
import com.google.shopping.merchant.products.v1.Condition;
import com.google.shopping.merchant.products.v1.InsertProductInputRequest;
import com.google.shopping.merchant.products.v1.ProductAttributes;
import com.google.shopping.merchant.products.v1.ProductInput;
import com.google.shopping.merchant.products.v1.ProductInputsServiceClient;
import com.google.shopping.merchant.products.v1.ProductInputsServiceSettings;
import com.google.shopping.merchant.products.v1.Shipping;
import com.google.shopping.type.Price;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to insert a product input */
public class InsertProductInputAsyncSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  private static String generateRandomString() {
    String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    Random random = new Random();
    StringBuilder sb = new StringBuilder(8);
    for (int i = 0; i < 8; i++) {
      sb.append(characters.charAt(random.nextInt(characters.length())));
    }
    return sb.toString();
  }

  private static ProductInput createRandomProduct() {
    Price price = Price.newBuilder().setAmountMicros(33_450_000).setCurrencyCode("USD").build();

    Shipping shipping =
        Shipping.newBuilder().setPrice(price).setCountry("GB").setService("1st class post").build();

    Shipping shipping2 =
        Shipping.newBuilder().setPrice(price).setCountry("FR").setService("1st class post").build();

    ProductAttributes attributes =
        ProductAttributes.newBuilder()
            .setTitle("A Tale of Two Cities")
            .setDescription("A classic novel about the French Revolution")
            .setLink("https://exampleWebsite.com/tale-of-two-cities.html")
            .setImageLink("https://exampleWebsite.com/tale-of-two-cities.jpg")
            .setAvailability(Availability.IN_STOCK)
            .setCondition(Condition.NEW)
            .setGoogleProductCategory("Media > Books")
            .addGtins("9780007350896")
            .addShipping(shipping)
            .addShipping(shipping2)
            .build();

    return ProductInput.newBuilder()
        .setContentLanguage("en")
        .setFeedLabel("CH")
        .setOfferId(generateRandomString())
        .setProductAttributes(attributes)
        .build();
  }

  public static void asyncInsertProductInput(Config config, String dataSource) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates a channel provider. This provider manages a pool of gRPC channels
    // to enhance throughput for bulk operations. Each individual channel in the pool
    // can handle up to approximately 100 concurrent requests.
    //
    // Channel: A single connection pathway to the service.
    // Pool: A collection of multiple channels managed by this provider.
    //   Requests are distributed across the channels in the pool.
    //
    // We recommend estimating the number of concurrent requests you'll make, divide by 50 (50%
    // utilization of channel capacity), and set the pool size to that number.
    InstantiatingGrpcChannelProvider channelProvider =
        InstantiatingGrpcChannelProvider.newBuilder().setPoolSize(30).build();

    // Creates service settings using the credentials retrieved above.
    ProductInputsServiceSettings productInputsServiceSettings =
        ProductInputsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .setTransportChannelProvider(channelProvider)
            .build();

    // Creates parent to identify where to insert the product.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (ProductInputsServiceClient productInputsServiceClient =
        ProductInputsServiceClient.create(productInputsServiceSettings)) {

      // Creates five insert product input requests with random product IDs.
      List<InsertProductInputRequest> requests = new ArrayList<>(5);
      for (int i = 0; i < 5; i++) {
        InsertProductInputRequest request =
            InsertProductInputRequest.newBuilder()
                .setParent(parent)
                // You can only insert products into datasource types of Input "API", and of Type
                // "Primary" or "Supplemental."
                // This field takes the `name` field of the datasource.
                .setDataSource(dataSource)
                // If this product is already owned by another datasource, when re-inserting, the
                // new datasource will take ownership of the product.
                .setProductInput(createRandomProduct())
                .build();

        requests.add(request);
      }

      System.out.println("Sending insert product input requests");
      List<ApiFuture<ProductInput>> futures =
          requests.stream()
              .map(
                  request ->
                      productInputsServiceClient.insertProductInputCallable().futureCall(request))
              .collect(Collectors.toList());

      // Creates callback to handle the responses when all are ready.
      ApiFuture<List<ProductInput>> responses = ApiFutures.allAsList(futures);
      ApiFutures.addCallback(
          responses,
          new ApiFutureCallback<List<ProductInput>>() {
            @Override
            public void onSuccess(List<ProductInput> results) {
              System.out.println("Inserted products below");
              System.out.println(results);
            }

            @Override
            public void onFailure(Throwable throwable) {
              System.out.println(throwable);
            }
          },
          MoreExecutors.directExecutor());

    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // Identifies the data source that will own the product input.
    String dataSource = "accounts/" + config.getAccountId() + "/dataSources/{datasourceId}";

    asyncInsertProductInput(config, dataSource);
  }
}

अगर customBatch का इस्तेमाल Content API में किया जाता है और Merchant API के लिए भी इस सुविधा की ज़रूरत है, तो हमें अपनी राय में इसकी वजह बताएं.

अनन्य विशेषताएं

आने वाली सुविधाएं, सिर्फ़ Merchant API में दिखेंगी. (कुछ अपवाद होंगे. जैसे, 2025 का सालाना फ़ीड स्पेसिफ़िकेशन.)

Merchant API के लिए उपलब्ध अनन्य सुविधाओं में ये शामिल हैं

  • Reviews API. Reviews API का इस्तेमाल करके, अपने प्रॉडक्ट और दुकान की रेटिंग को लागू और मैनेज करें. ज़्यादा जानकारी के लिए, सेलर की समीक्षा और प्रॉडक्ट की समीक्षा देखें.
  • सूचनाएं: किसी खाते के प्रॉडक्ट डेटा में होने वाले बदलावों के लिए पुश सूचनाएं पाने के लिए साइन अप करें.

कीमत

Merchant Common पैकेज में, Price के लिए ये बदलाव किए गए हैं:

Content API for Shopping Merchant API
रकम फ़ील्ड value:string amountMicros:int64
मुद्रा फ़ील्ड currency:string currencyCode:string

Price की रकम अब माइक्रो में रिकॉर्ड की जाती है. इसमें 10 लाख माइक्रो, आपकी मुद्रा की स्टैंडर्ड यूनिट के बराबर होते हैं.

Content API for Shopping में, Price एक स्ट्रिंग के तौर पर डेसिमल नंबर था.

रकम फ़ील्ड का नाम value से बदलकर amountMicros कर दिया गया है

मुद्रा फ़ील्ड का नाम currency से बदलकर currencyCode कर दिया गया है. फ़ॉर्मैट अब भी ISO 4217 है.

लेटेस्ट अपडेट और एलान

ज़्यादा जानकारी वाले अपडेट के लिए, हर सब-एपीआई के लिए रिलीज़ नोट देखें. Merchant API के ज़्यादा नियमित तौर पर इकट्ठा किए गए अपडेट के लिए, हमारे लेटेस्ट अपडेट देखें.

ज़्यादा जानकारी पाने और Merchant API के बारे में ज़्यादा जानने के लिए, हमारी डेवलपर साइट खास जानकारी और ज़्यादा जानकारी के लिए, माइग्रेशन की पूरी गाइड देखें.

Merchant API और इसके सब-एपीआई के बारे में जानने के लिए, Merchant API का डिज़ाइन देखें.