শপিং সামঞ্জস্যের জন্য সামগ্রী API

আপনি কেনাকাটা বাস্তবায়নের জন্য আপনার বিদ্যমান সামগ্রী API এর সাথে বণিক API একীভূত করতে এই নির্দেশিকা ব্যবহার করতে পারেন।

মার্চেন্ট এপিআই আপনাকে বণিক কেন্দ্রে অ্যাকাউন্ট-, পণ্য- এবং ইনভেন্টরি-সম্পর্কিত পরিচালনা কর্মপ্রবাহগুলি স্বয়ংক্রিয় করতে দেয়। বণিক API ব্যবহারের ক্ষেত্রে অন্তর্ভুক্ত:

  • স্বয়ংক্রিয় অ্যাকাউন্ট পরিচালনা
  • স্বয়ংক্রিয় পণ্য ব্যবস্থাপনা
  • স্বয়ংক্রিয় জায় ব্যবস্থাপনা
  • কাস্টম রিপোর্টিং

বিষয়বস্তু API এর উপর উন্নতি

মার্চেন্ট এপিআই নিম্নলিখিত ক্ষেত্রগুলিতে কন্টেন্ট এপিআই-এর চেয়ে উন্নতি করে:

শুরু করুন

মার্চেন্ট এপিআই এবং এর সাব-এপিআই সম্পর্কে বিস্তারিত জানার জন্য মার্চেন্ট এপিআই ডিজাইন দেখুন।

মার্চেন্ট এপিআই ব্যবহার শুরু করতে, আপনার অনুরোধের URLগুলিকে নিম্নলিখিত ফর্ম্যাটে পরিবর্তন করুন:

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

আরও তথ্যের জন্য, কুইকস্টার্ট গাইড এবং মার্চেন্ট এপিআই রেফারেন্স দেখুন।

জিআরপিসি সমর্থন

মার্চেন্ট API gRPC এবং REST সমর্থন করে। আপনি একই সময়ে বণিক API-এর জন্য gRPC এবং কেনাকাটার জন্য সামগ্রী API-এর জন্য REST ব্যবহার করতে পারেন।

মার্চেন্ট এপিআই ক্লায়েন্ট লাইব্রেরির জন্য gRPC প্রয়োজন।

আরও তথ্যের জন্য gRPC ব্যবহার দেখুন।

সামঞ্জস্য

এই নির্দেশিকাটি সাধারণ পরিবর্তনগুলি বর্ণনা করে যা সমগ্র মার্চেন্ট API-এ প্রযোজ্য। নির্দিষ্ট বৈশিষ্ট্য পরিবর্তনের জন্য নিম্নলিখিত নির্দেশিকা দেখুন:

Merchant API শপিং v2.1 বৈশিষ্ট্যের জন্য বিদ্যমান সামগ্রী API-এর পাশাপাশি কাজ করার জন্য ডিজাইন করা হয়েছে।

উদাহরণস্বরূপ, আপনি শপিং v2.1 products বাস্তবায়নের জন্য আপনার বিদ্যমান সামগ্রী API-এর পাশাপাশি মার্চেন্ট ইনভেন্টরি API ব্যবহার করতে পারেন। আপনি একটি নতুন স্থানীয় পণ্য আপলোড করতে শপিংয়ের জন্য সামগ্রী API ব্যবহার করতে পারেন (যেটি আপনি স্থানীয় দোকানে বিক্রি করেন), তারপর সেই পণ্যের জন্য ইন-স্টোর তথ্য পরিচালনা করতে মার্চেন্ট ইনভেন্টরিস এপিআই LocalInventory সংস্থান ব্যবহার করুন।

ব্যাচ অনুরোধ

Merchant API কেনাকাটার জন্য সামগ্রী API-তে বৈশিষ্ট্যযুক্ত customBatch পদ্ধতি সমর্থন করে না। পরিবর্তে, একবারে একাধিক অনুরোধ পাঠান বা অ্যাসিঙ্ক্রোনাসভাবে আপনার কলগুলি চালান দেখুন।

নিম্নলিখিত নমুনা প্রদর্শন করে কিভাবে একটি পণ্য ইনপুট সন্নিবেশ করতে হয়।

জাভা
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.auth.oauth2.GoogleCredentials;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.shopping.merchant.products.v1beta.Attributes;
import com.google.shopping.merchant.products.v1beta.InsertProductInputRequest;
import com.google.shopping.merchant.products.v1beta.ProductInput;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceClient;
import com.google.shopping.merchant.products.v1beta.ProductInputsServiceSettings;
import com.google.shopping.merchant.products.v1beta.Shipping;
import com.google.shopping.type.Channel.ChannelEnum;
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();

    Attributes attributes =
        Attributes.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("in stock")
            .setCondition("new")
            .setGoogleProductCategory("Media > Books")
            .setGtin(0, "9780007350896")
            .addShipping(shipping)
            .addShipping(shipping2)
            .build();

    return ProductInput.newBuilder()
        .setChannel(ChannelEnum.ONLINE)
        .setContentLanguage("en")
        .setFeedLabel("CH")
        .setOfferId(generateRandomString())
        .setAttributes(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 service settings using the credentials retrieved above.
    ProductInputsServiceSettings productInputsServiceSettings =
        ProductInputsServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .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 "FILE", 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);
  }
}

আপনি যদি Content API-এ customBatch ব্যবহার করেন এবং মার্চেন্ট API-এর জন্য এই বৈশিষ্ট্যটির প্রয়োজন হয়, তাহলে আপনার প্রতিক্রিয়াতে কেন তা আমাদের জানান।

শনাক্তকারী

Google এর API উন্নতি নীতিগুলির সাথে সারিবদ্ধ করতে, আমরা মার্চেন্ট API সংস্থানগুলির শনাক্তকারীগুলিতে কিছু পরিবর্তন করেছি৷

নাম আইডি প্রতিস্থাপন করে

সমস্ত মার্চেন্ট API সংস্থান তাদের অনন্য শনাক্তকারী হিসাবে name ক্ষেত্রটি ব্যবহার করে।

আপনার কলগুলিতে name ক্ষেত্রটি কীভাবে ব্যবহার করবেন তার একটি উদাহরণ এখানে রয়েছে:

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

এই নতুন name ক্ষেত্রটি মার্চেন্ট এপিআই-এ সমস্ত রিড এবং রাইট কলের জন্য রিসোর্স শনাক্তকারী হিসাবে ফেরত দেওয়া হয়।

উদাহরণ স্বরূপ, একটি রিসোর্স থেকে name পুনরুদ্ধার করার জন্য একটি getName() পদ্ধতি প্রয়োগ করুন এবং বণিক ও রিসোর্স আইডি থেকে name তৈরি করার পরিবর্তে একটি পরিবর্তনশীল হিসাবে আউটপুট সংরক্ষণ করুন।

শিশু সম্পদের জন্য পিতামাতার ক্ষেত্র

মার্চেন্ট API-এ, সমস্ত চাইল্ড রিসোর্সের parent ক্ষেত্র থাকে। আপনি সন্তানকে সন্নিবেশ করার জন্য সম্পদের name উল্লেখ করতে parent ক্ষেত্রটি ব্যবহার করতে পারেন, পুরো অভিভাবক সম্পদ পাস করার পরিবর্তে। আপনি সেই parent শিশু সম্পদের তালিকা করতে list পদ্ধতি সহ parent ক্ষেত্রটিও ব্যবহার করতে পারেন।

উদাহরণস্বরূপ, একটি প্রদত্ত পণ্যের জন্য স্থানীয় জায় তালিকাভুক্ত করতে, list পদ্ধতির জন্য parent ক্ষেত্রে পণ্যের name উল্লেখ করুন। এই ক্ষেত্রে, প্রদত্ত product ফেরত দেওয়া LocalInventory সম্পদের parent

প্রকারভেদ

এখানে মার্চেন্ট API সাব-এপিআই জুড়ে শেয়ার করা কিছু সাধারণ প্রকার রয়েছে।

দাম

মার্চেন্ট কমন প্যাকেজে Price জন্য কী পরিবর্তন করা হয়েছে তা এখানে:

বিষয়বস্তু API বণিক API
পরিমাণ ক্ষেত্র value:string amountMicros:int64
মুদ্রা ক্ষেত্র currency:string currencyCode:string

Price পরিমাণ এখন মাইক্রোতে রেকর্ড করা হয়েছে, যেখানে 1 মিলিয়ন মাইক্রো আপনার মুদ্রার স্ট্যান্ডার্ড ইউনিটের সমতুল্য।

কেনাকাটার জন্য সামগ্রী API-তে, Price একটি স্ট্রিং আকারে একটি দশমিক সংখ্যা ছিল।

পরিমাণ ক্ষেত্রের নাম value থেকে পরিবর্তিত হয়েছে amountMicros

মুদ্রা ক্ষেত্রের নাম currency থেকে currencyCode কোডে পরিবর্তিত হয়েছে। ফর্ম্যাটটি ISO 4217 হিসাবে রয়ে গেছে।