使用 Google Apps 脚本将 Shopify 客户数据导入 Google 表格

问题描述 投票:0回答:1

我正在尝试从 Shopify 获取客户数据,但在 API 响应中找不到一个参数。以下是截图:

enter image description here

我想获得绿色包围的值

June 6,7,8
。这是我正在使用的代码片段:

function getShopifyData() {
  var url = "https://your-shopify-store.myshopify.com/admin/api/2024-04/customers.json";
  var username = "###"; // API Key
  var password = "###"; // Access Token
  var response = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Basic ' + Utilities.base64Encode(username + ':' + password)
    }
  });

  var jsonData = JSON.parse(response.getContentText());
  console.log(jsonData);
}

JSON response
看起来像这样,但是我找不到日期
June 6,7,8

[ { id: 83105908183,
       email: 'mail',
       created_at: '2024-05-24T14:45:04+08:00',
       updated_at: '2024-05-24T14:45:04+08:00',
       first_name: 'name',
       last_name: 'name2',
       orders_count: 0,
       state: 'disabled',
       total_spent: '0.00',
       last_order_id: null,
       note: null,
       verified_email: true,
       multipass_identifier: null,
       tax_exempt: false,
       tags: '',
       last_order_name: null,
       currency: 'AUD',
       phone: null,
       addresses: [Object],
       tax_exemptions: [],
       email_marketing_consent: [Object],
       sms_marketing_consent: null,
       admin_graphql_api_id: 'gid://shopify/Customer/83105908183',
       default_address: [Object] }]

如果您能指导我获得这个领域,我将非常感激。

google-sheets google-apps-script shopify
1个回答
0
投票

我不完全确定这些信息在哪里,但我有两个想法:

  • 信息是否包含在customers.json中?它可能与不同的实体有关吗?

  • 信息到底与什么相关,例如可能是 json 返回的嵌套对象的一部分,应该作为对象属性进行访问 例如:

      jsonData.forEach(function(customer) {
      console.log(JSON.stringify(customer, null, 2));
      if (customer.addresses) {
        console.log("Addresses: " + JSON.stringify(customer.addresses, null, 2));
      }
      if (customer.email_marketing_consent) {
        console.log("Email Marketing Consent: " + JSON.stringify(customer.email_marketing_consent, null, 2));
      }
      if (customer.default_address) {
        console.log("Default Address: " + JSON.stringify(customer.default_address, null, 2));
      }
    });
    

我的2美分。

© www.soinside.com 2019 - 2024. All rights reserved.