शॉपिंग कॉन्टेंट सर्विस

Apps Script में शॉपिंग के लिए, प्रॉडक्ट लिस्टिंग और Merchant Center खातों को मैनेज करने की सुविधा मिलती है.

Shopping Content Service की मदद से, Google Apps Script में Google Content API for Shopping का इस्तेमाल किया जा सकता है. इस एपीआई की मदद से, Google Merchant Center के उपयोगकर्ता अपने प्रॉडक्ट लिस्टिंग अपलोड और मैनेज कर सकते हैं. साथ ही, अपने Merchant Center खातों को मैनेज कर सकते हैं.

इस सेवा के बारे में ज़्यादा जानकारी के लिए, Google Content API for Shopping के लिए रेफ़रंस दस्तावेज़ देखें. Apps Script में मौजूद सभी ऐडवांस सेवाओं की तरह, Shopping Content Service भी सार्वजनिक एपीआई के ऑब्जेक्ट, तरीकों, और पैरामीटर का इस्तेमाल करती है.

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

रेफ़रंस

इस सेवा के बारे में ज़्यादा जानकारी के लिए, Google Content API for Shopping API के लिए रेफ़रंस दस्तावेज़ देखें. Apps Script की सभी ऐडवांस सेवाओं की तरह, Shopping Content सेवा भी सार्वजनिक एपीआई के ऑब्जेक्ट, तरीकों, और पैरामीटर का इस्तेमाल करती है. ज़्यादा जानकारी के लिए, तरीके के सिग्नेचर कैसे तय किए जाते हैं लेख पढ़ें.

समस्याओं की शिकायत करने और अन्य सहायता पाने के लिए, Google Content API for Shopping की सहायता गाइड देखें.

नमूना कोड

अब हम Shopping Content Service की कुछ सुविधाओं का इस्तेमाल करने का तरीका दिखाएंगे.

प्रॉडक्ट डालें

इस उदाहरण में, किसी Merchant Center खाते में एक प्रॉडक्ट डालने का तरीका बताया गया है.

advanced/shoppingContent.gs
/**
 * Inserts a product into the products list. Logs the API response.
 */
function productInsert() {
  const merchantId = 123456; // Replace this with your Merchant Center ID.
  // Create a product resource and insert it
  const productResource = {
    offerId: "book123",
    title: "A Tale of Two Cities",
    description: "A classic novel about the French Revolution",
    link: "http://my-book-shop.com/tale-of-two-cities.html",
    imageLink: "http://my-book-shop.com/tale-of-two-cities.jpg",
    contentLanguage: "en",
    targetCountry: "US",
    channel: "online",
    availability: "in stock",
    condition: "new",
    googleProductCategory: "Media > Books",
    productType: "Media > Books",
    gtin: "9780007350896",
    price: {
      value: "2.50",
      currency: "USD",
    },
    shipping: [
      {
        country: "US",
        service: "Standard shipping",
        price: {
          value: "0.99",
          currency: "USD",
        },
      },
    ],
    shippingWeight: {
      value: "2",
      unit: "pounds",
    },
  };

  try {
    response = ShoppingContent.Products.insert(productResource, merchantId);
    // RESTful insert returns the JSON object as a response.
    console.log(response);
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log("Failed with error: $s", e.error);
  }
}

प्रॉडक्ट की लिस्टिंग करना

इस उदाहरण में बताया गया है कि किसी Merchant Center खाते के लिए, अपने प्रॉडक्ट कैसे लिस्ट किए जा सकते हैं.

advanced/shoppingContent.gs
/**
 * Lists the products for a given merchant.
 */
function productList() {
  const merchantId = 123456; // Replace this with your Merchant Center ID.
  let pageToken;
  let pageNum = 1;
  const maxResults = 10;
  try {
    do {
      const products = ShoppingContent.Products.list(merchantId, {
        pageToken: pageToken,
        maxResults: maxResults,
      });
      console.log(`Page ${pageNum}`);
      if (products.resources) {
        for (let i = 0; i < products.resources.length; i++) {
          console.log(`Item [${i}] ==> ${products.resources[i]}`);
        }
      } else {
        console.log(`No more products in account ${merchantId}`);
      }
      pageToken = products.nextPageToken;
      pageNum++;
    } while (pageToken);
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log("Failed with error: $s", e.error);
  }
}

एक साथ कई प्रॉडक्ट डालें

इस उदाहरण में, एक साथ तीन प्रॉडक्ट डालने के लिए Products.custombatch का इस्तेमाल किया गया है.

advanced/shoppingContent.gs
/**
 * Batch updates products. Logs the response.
 * @param  {object} productResource1 The first product resource.
 * @param  {object} productResource2 The second product resource.
 * @param  {object} productResource3 The third product resource.
 */
function custombatch(productResource1, productResource2, productResource3) {
  const merchantId = 123456; // Replace this with your Merchant Center ID.
  custombatchResource = {
    entries: [
      {
        batchId: 1,
        merchantId: merchantId,
        method: "insert",
        productId: "book124",
        product: productResource1,
      },
      {
        batchId: 2,
        merchantId: merchantId,
        method: "insert",
        productId: "book125",
        product: productResource2,
      },
      {
        batchId: 3,
        merchantId: merchantId,
        method: "insert",
        productId: "book126",
        product: productResource3,
      },
    ],
  };
  try {
    const response = ShoppingContent.Products.custombatch(custombatchResource);
    console.log(response);
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log("Failed with error: $s", e.error);
  }
}

खाता-लेवल पर टैक्स अपडेट करना

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

advanced/shoppingContent.gs
/**
 * Updates content account tax information.
 * Logs the API response.
 */
function updateAccountTax() {
  // Replace this with your Merchant Center ID.
  const merchantId = 123456;

  // Replace this with the account that you are updating taxes for.
  const accountId = 123456;

  try {
    const accounttax = ShoppingContent.Accounttax.get(merchantId, accountId);
    console.log(accounttax);

    const taxInfo = {
      accountId: accountId,
      rules: [
        {
          useGlobalRate: true,
          locationId: 21135,
          shippingTaxed: true,
          country: "US",
        },
        {
          ratePercent: 3,
          locationId: 21136,
          country: "US",
        },
        {
          ratePercent: 2,
          locationId: 21160,
          shippingTaxed: true,
          country: "US",
        },
      ],
    };

    console.log(
      ShoppingContent.Accounttax.update(taxInfo, merchantId, accountId),
    );
  } catch (e) {
    // TODO (Developer) - Handle exceptions
    console.log("Failed with error: $s", e.error);
  }
}