Request:

– Đăng sản phẩm số lượng lớn lên Google Business profile

– Đã có sẵn list sản phẩm (variable/variation) trên google sheet => chỉ cần sử dụng content của variable (chú ý check yêu cầu về nội dung của Google)

– Sử dụng apps script để tự động post toàn bộ các sản phẩm (có thể asign vào button hoặc set trigger chạy theo giờ)

Workflow:

– Setup authentication for the script in Google Business API

– Write the script: get all data from script => using loop to run through all products => publish on GB profile

– Document of API:

+ https://developers.google.com/my-business/reference/rest/v4/accounts.locations.localPosts

+ https://developers.google.com/my-business/content/overview

+ https://developers.google.com/my-business/content/basic-setup

 

Sample script:

function postProducts() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  
  for (var i = 1; i < data.length; i++) {
    var product = {
      "title": data[i][0],
      "description": data[i][1],
      "price": {
        "currencyCode": data[i][2],
        "units": data[i][3],
        "nanos": data[i][4] * 1000000
      }
    };
    var requestBody = {
      "product": product
    };
    var locationId = 'INSERT_LOCATION_ID_HERE';
    var response = Maps.newHttpRequest()
      .setMethod('POST')
      .setContentType('application/json')
      .setOAuthToken(ScriptApp.getOAuthToken())
      .setUrl('https://mybusiness.googleapis.com/v4/accounts/ACCOUNT_ID/locations/' + locationId + '/localInventory/products')
      .setContent(JSON.stringify(requestBody))
      .fetch();
    Logger.log(response.getContentText());
  }
}

INSERT_LOCATION_ID_HERE: the ID of the location 

ACCOUNT_ID: Google My Business account ID.

Note: Make sure that the column order in the spreadsheet matches the order of the fields in the product object. Also, ensure that the data types match the expected data types (e.g. price units and nanos should be numbers).

 

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *