Shopping-Inhaltsdienst

Mit dem Shopping-Inhaltsdienst können Sie die Google Content API for Shopping in Apps Script verwenden. Mit dieser API können Google Merchant Center-Nutzer ihre Produkteinträge hochladen und verwalten sowie ihre Merchant Center-Konten verwalten.

Ausführliche Informationen zu diesem Dienst finden Sie in der Referenzdokumentation zur Google Content API for Shopping. Wie alle erweiterten Dienste in Apps Script verwendet auch der Shopping-Inhaltsdienst die gleichen Objekte, Methoden und Parameter wie die öffentliche API.

Referenz

Ausführliche Informationen zu diesem Dienst finden Sie in der Referenzdokumentation zur Google Content API for Shopping API. Wie alle erweiterten Dienste in Apps Script verwendet der erweiterte Google Tabellen-Dienst dieselben Objekte, Methoden und Parameter wie die öffentliche API. Weitere Informationen finden Sie unter So werden Methodensignaturen ermittelt.

Wie Sie Probleme melden und weiteren Support erhalten, erfahren Sie im Supportleitfaden für die Google Content API for Shopping.

Beispielcode

Wir zeigen Ihnen nun, wie Sie einige Funktionen des Inhaltsdienstes für Google Shopping nutzen können.

Produkt einfügen

In diesem Beispiel wird gezeigt, wie Sie ein einzelnes Produkt in ein bestimmtes Merchant Center-Konto einfügen.

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);
  }
}

Produkte auflisten

In diesem Beispiel wird gezeigt, wie Sie Ihre Produkte für ein bestimmtes Merchant Center-Konto auflisten.

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);
  }
}

Produkte im Batch einfügen

In diesem Beispiel wird Products.custombatch verwendet, um drei Produkte gleichzeitig einzufügen.

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);
  }
}

Steuern auf Kontoebene aktualisieren

In diesem Beispielcode wird Accounttax verwendet, um die Steuerinformationen auf Kontoebene für ein Merchant Center-Konto zu aktualisieren. Weitere Informationen zu Steuern und Versandkosten auf Kontoebene finden Sie im API-Leitfaden.

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);
  }
}