বণিক API পরিষেবা

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

মার্চেন্ট API সম্পর্কে বিস্তারিত তথ্যের জন্য, রেফারেন্স ডকুমেন্টেশন দেখুন। Apps Script-এর সমস্ত উন্নত পরিষেবার মতো, Merchant API পরিষেবা পাবলিক API হিসাবে একই বস্তু, পদ্ধতি এবং প্যারামিটার ব্যবহার করে৷

মার্চেন্ট এপিআই হল সাব-এপিআই-এর একটি সংগ্রহ, যেগুলি সম্পর্কিত পরিষেবা এবং সংস্থানগুলির গোষ্ঠী৷ এখানে সাব-এপিআই-এর তালিকা রয়েছে।

অ্যাপস স্ক্রিপ্টে মার্চেন্ট API পরিষেবা ব্যবহার করতে, নিম্নলিখিত বিকল্পগুলির মধ্যে একটি ব্যবহার করে অ্যাপস স্ক্রিপ্ট উন্নত পরিষেবাগুলি সক্ষম করুন:

  1. নতুন প্রকল্পের জন্য appsscript.json সক্ষম করুন । আমরা নতুন Apps স্ক্রিপ্ট প্রকল্পগুলির জন্য এই বিকল্পটি সুপারিশ করি৷

  2. বিদ্যমান প্রকল্পগুলির জন্য Apps স্ক্রিপ্ট সক্ষম করুন ৷ বিদ্যমান প্রকল্পগুলিতে অতিরিক্ত সাব-এপিআই সক্ষম করতে এই পদ্ধতিটি ব্যবহার করুন।

appsscript.json এ এপিআই সক্ষম করুন

নিম্নলিখিত উদাহরণটি একটি appsscript.json ফাইল দেখায় যা পণ্য, অ্যাকাউন্ট, প্রতিবেদন এবং ডেটা উত্স সাব-এপিআই সক্ষম করে৷

  1. অ্যাপস স্ক্রিপ্ট এডিটরে, প্রজেক্ট সেটিংস ক্লিক করুন।

  2. সম্পাদক বিকল্পে "appsscript.json" ম্যানিফেস্ট ফাইল দেখান সক্ষম করুন৷

  3. সম্পাদকে, appsscript.json ফাইলটি নির্বাচন করুন।

  4. আপনার appsscript.json ফাইলের বিষয়বস্তু নিচের সাথে প্রতিস্থাপন করুন:

    {
      "dependencies": {
        "enabledAdvancedServices": [
          {
            "userSymbol": "MerchantApiAccounts",
            "version": "accounts_v1beta",
            "serviceId": "merchantapi"
          },
          {
            "userSymbol": "MerchantApiDataSources",
            "version": "datasources_v1beta",
            "serviceId": "merchantapi"
          },
          {
            "userSymbol": "MerchantApiProducts",
            "version": "products_v1beta",
            "serviceId": "merchantapi"
          },
          {
            "userSymbol": "MerchantApiReports",
            "version": "reports_v1beta",
            "serviceId": "merchantapi"
          }
        ]
      },
      "exceptionLogging": "STACKDRIVER",
      "runtimeVersion": "V8"
    }
    
  5. Save এ ক্লিক করুন।

  6. আপনি এখন আপনার কোডের মধ্যে নিম্নলিখিত সাব-এপিআইগুলি উল্লেখ করতে পারেন:

    MerchantApiAccounts

    খ. MerchantApiDataSources

    গ. MerchantApiProducts

    d MerchantApiReports

অতিরিক্ত সাব-এপিআই বা বিদ্যমান প্রকল্পগুলির জন্য Apps স্ক্রিপ্ট সক্ষম করুন৷

বিদ্যমান প্রকল্পগুলিতে সাব-এপিআই সক্ষম করতে নিম্নলিখিত পদক্ষেপগুলি ব্যবহার করুন৷

  1. আপনার Apps স্ক্রিপ্ট প্রকল্প খুলুন.

  2. বাম দিকে, এডিটর < > ক্লিক করুন।

  3. বাম দিকে, পরিষেবাগুলির পাশে, একটি পরিষেবা যোগ করুন + ক্লিক করুন।

  4. সংস্করণ নির্বাচকের মধ্যে আপনি যে সাব-এপিআই সক্ষম করতে চান সেটি নির্বাচন করুন।

  5. আপনার সাব-এপিআই-এর নামের সাথে শনাক্তকারী যোগ করুন। উদাহরণস্বরূপ, Inventories সাব-API সক্ষম করতে, inventories_v1beta সংস্করণ নির্বাচন করুন এবং সনাক্তকারীকে MerchantApiInventories- এ পরিবর্তন করুন।

  6. আপনি এখন আপনার কোডের মধ্যে Inventories সাব-API-কে MerchantApiInventories হিসাবে উল্লেখ করতে পারেন।

নমুনা কোড

এই বিভাগটি ব্যাখ্যা করে যে কীভাবে নির্বাচিত বৈশিষ্ট্যের জন্য মার্চেন্ট এপিআই ব্যবহার করতে হয়।

পণ্য তালিকা

এই উদাহরণটি দেখায় যে কীভাবে একটি প্রদত্ত বণিক কেন্দ্র অ্যাকাউন্টের জন্য পণ্য তালিকাভুক্ত করতে হয়।


/**
 * Lists all products for a given Merchant Center account.
 */
function productList() {
  // IMPORTANT:
  // Enable the Merchant API Products Bundle Advanced Service and call it
  // "MerchantApiProducts"

  // Replace this with your Merchant Center ID.
  const accountId = '<MERCHANT_CENTER_ID>';

  // Construct the parent name
  const parent = 'accounts/' + accountId;

  try {
    console.log('Sending list Products request');
    let pageToken;
    // Set the page size to 1000. This is the maximum allowed page size.
    let pageSize = 1000;

    console.log('Retrieved products below:');
    // Call the Products.list API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response = MerchantApiProducts.Accounts.Products.list(parent, {pageToken, pageSize});
      console.log(response);
      pageToken = response.nextPageToken;
    } while (pageToken); // Exits when there is no next page token.
  } catch (e) {
    console.log('ERROR!');
    console.log(e);
  }
}

ফিল্টার অননুমোদিত পণ্য

এই উদাহরণটি দেখায় কিভাবে একটি বণিক কেন্দ্র অ্যাকাউন্টে অস্বীকৃত পণ্য ফিল্টার করতে হয়।


/**
 * Demonstrates how to filter disapproved products using the Merchant API Reports service.
 */
function filterDisapprovedProducts() {
  // IMPORTANT:
  // Enable the Merchant API Reports Bundle Advanced Service and call it
  // "MerchantApiReports"
  // Enable the Merchant API Products Bundle Advanced Service and call it
  // "MerchantApiProducts"

  // Replace this with your Merchant Center ID.
  const accountId = '<INSERT_MERCHANT_CENTER_ID>';

  // Construct the parent name
  const parent = 'accounts/' + accountId;

  try {
    console.log('Sending search Report request');
    // Set pageSize to the maximum value (default: 1000)
    let pageSize = 1000;
    let pageToken;
    // The query below is an example of a query for the productView that gets product informations
    // for all disapproved products.
    let query = 'SELECT offer_id,' +
        'id,' +
        'price,' +
        'title' +
        ' FROM product_view' +
        ' WHERE aggregated_reporting_context_status = "NOT_ELIGIBLE_OR_DISAPPROVED"';


    // Call the Reports.search API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response =
          MerchantApiReports.Accounts.Reports.search({query, pageSize, pageToken}, parent);
      for (const reportRow of response.results) {
        console.log("Printing data from Product View:");
        console.log(reportRow);

        // OPTIONALLY, you can get the full product details by calling the GetProduct method.
        let productName = parent + "/products/" + reportRow.getProductView().getId();
        product = MerchantApiProducts.Accounts.Products.get(productName);
        console.log(product);
      }
      pageToken = response.nextPageToken;
    } while (pageToken);  // Exits when there is no next page token.

  } catch (e) {
    console.log('ERROR!');
    console.log('Error message:' + e.message);
  }
}

একটি প্রদত্ত অ্যাকাউন্টের জন্য একটি প্রতিবেদন পুনরুদ্ধার করুন৷

এই উদাহরণটি দেখায় যে কীভাবে একটি প্রদত্ত বণিক কেন্দ্র অ্যাকাউন্টের জন্য একটি প্রতিবেদন পুনরুদ্ধার করতে হয়।


/**
 * Searches a report for a given Merchant Center account.
 */
function searchReport() {
  // IMPORTANT:
  // Enable the Merchant API Reports Bundle Advanced Service and call it
  // "MerchantApiReports"

  // Replace this with your Merchant Center ID.
  const accountId = '<MERCHANT_CENTER_ID>';

  // Construct the parent name
  const parent = 'accounts/' + accountId;

  try {
    console.log('Sending search Report request');
    // Set pageSize to the maximum value (default: 1000)
    let pageSize = 1000;
    let pageToken;
    // Uncomment the desired query from below. Documentation can be found at
    // https://developers.google.com/merchant/api/reference/rest/reports_v1beta/accounts.reports#ReportRow
    // The query below is an example of a query for the product_view.
    let query = 'SELECT offer_id,' +
        'id,' +
        'price,' +
        'gtin,' +
        'item_issues,' +
        'channel,' +
        'language_code,' +
        'feed_label,' +
        'title,' +
        'brand,' +
        'category_l1,' +
        'product_type_l1,' +
        'availability,' +
        'shipping_label,' +
        'thumbnail_link,' +
        'click_potential' +
        ' FROM product_view';

    /*
    // The query below is an example of a query for the
    price_competitiveness_product_view. let query = "SELECT offer_id,"
                 + "id,"
                 + "benchmark_price,"
                 + "report_country_code,"
                 + "price,"
                 + "title,"
                 + "brand,"
                 + "category_l1,"
                 + "product_type_l1"
                + " FROM price_competitiveness_product_view"
                + " WHERE date BETWEEN '2023-03-03' AND '2025-03-10'"; */
    /*
    // The query below is an example of a query for the
    price_insights_product_view. let query = "SELECT offer_id,"
                     + "id,"
                     + "suggested_price,"
                     + "price,"
                     + "effectiveness,"
                     + "title,"
                     + "brand,"
                     + "category_l1,"
                     + "product_type_l1,"
                     + "predicted_impressions_change_fraction,"
                     + "predicted_clicks_change_fraction,"
                     + "predicted_conversions_change_fraction"
                    + " FROM price_insights_product_view"; */

    /*
    // The query below is an example of a query for the
    product_performance_view. let query = "SELECT offer_id,"
            + "conversion_value,"
            + "marketing_method,"
            + "customer_country_code,"
            + "title,"
            + "brand,"
            + "category_l1,"
            + "product_type_l1,"
            + "custom_label0,"
            + "clicks,"
            + "impressions,"
            + "click_through_rate,"
            + "conversions,"
            + "conversion_rate"
            + " FROM product_performance_view"
            + " WHERE date BETWEEN '2023-03-03' AND '2025-03-10'"; */

    // Call the Reports.search API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response =
          MerchantApiReports.Accounts.Reports.search({query, pageSize, pageToken}, parent);
      for (const reportRow of response.results) {
        console.log(reportRow);
      }
      pageToken = response.nextPageToken;
    } while (pageToken);  // Exits when there is no next page token.

  } catch (e) {
    console.log('ERROR!');
    console.log(e);
    console.log('Error message:' + e.message);
    if (e.stack) {
      console.log('Stack trace:' + e.stack);
    }
  }
}


সমস্ত তথ্য উত্স তালিকা

এই উদাহরণটি দেখায় যে কীভাবে একটি প্রদত্ত বণিক কেন্দ্র অ্যাকাউন্টে সমস্ত ডেটা উত্স তালিকাভুক্ত করতে হয়৷


/**
 * Lists all data sources for a given Merchant Center account.
 */
function listDataSources() {
  // IMPORTANT:
  // Enable the Merchant API DataSources Bundle Advanced Service and call it
  // "MerchantApiDataSources"

  // Replace this with your Merchant Center ID.
  const accountId = '<MERCHANT_CENTER_ID>';

  // Construct the parent name
  const parent = 'accounts/' + accountId;
  let dataSources = [];
  let primaryDataSources = [];
  try {
    console.log('Sending list DataSources request');
    let pageToken;
    let pageSize = 10;
    // Call the DataSources.list API method. Use the pageToken to iterate through
    // all pages of results.
    do {
      response =
          MerchantApiDataSources.Accounts.DataSources.list(parent, {pageSize, pageToken});
      for (const datasource of response.dataSources) {
        dataSources.push(datasource);
        if (datasource.primaryProductDataSource) {
          primaryDataSources.push(datasource);
        }
      }
      pageToken = response.nextPageToken;
    } while (pageToken);  // Exits when there is no next page token.
    console.log('Retrieved ' + dataSources.length + ' data sources.');
    console.log(
        'There were ' + primaryDataSources.length +
        ' primary product data sources.');
  } catch (e) {
    console.log('ERROR!');
    console.log(e);
  }
}