无法使用 Google Apps 脚本将新产品上传到 shopify

Unable to upload new product to shopify using Google Apps Script

我已经尝试了很多,但我仍然无法 post 使用 Apps 脚本将产品添加到 shopify 商店。我使用的是正确的密钥和密码,但它不起作用。我没有收到任何错误,但我在响应中得到了我商店中所有产品的列表。

这是我的代码

var storeName = ""
var key = ""
var secret = ""
uRL = "https://"+storeName+".myshopify.com/admin/api/2021-10/products.json"
params = {
    "headers": {
    "method":"POST",
    "Authorization": "Basic " + Utilities.base64Encode(key+":"+secret),
    "contentType":"application/json",
    "charset":"utf-8"
    },
    "products": {
        "product": {
            "body_html":"",
            "product_type": "JEWELLERY - Bracelets",
            "published_scope": "global",
            "title":"Burton Custom Freestyle 151",
            "vendor":storeName,
            "status":"active",
            "published":true,
            "tags":"",
            "price":"100"
        }
    },
    "muteHttpExceptions" : true
}
var response = UrlFetchApp.fetch(uRL, params);
var r = JSON.parse(response)
console.info(r)

你的情况,下面的修改怎么样?

发件人:

params = {
    "headers": {
    "method":"POST",
    "Authorization": "Basic " + Utilities.base64Encode(key+":"+secret),
    "contentType":"application/json",
    "charset":"utf-8"
    },
    "products": {
        "product": {
            "body_html":"",
            "product_type": "JEWELLERY - Bracelets",
            "published_scope": "global",
            "title":"Burton Custom Freestyle 151",
            "vendor":storeName,
            "status":"active",
            "published":true,
            "tags":"",
            "price":"100"
        }
    },
    "muteHttpExceptions" : true
}

收件人:

var params = {
  "method": "POST",
  "headers": { "Authorization": "Basic " + Utilities.base64Encode(key + ":" + secret) },
  "contentType": "application/json",
  "muteHttpExceptions": true,
  "payload": JSON.stringify({
    "products": {
      "product": {
        "body_html": "",
        "product_type": "JEWELLERY - Bracelets",
        "published_scope": "global",
        "title": "Burton Custom Freestyle 151",
        "vendor": storeName,
        "status": "active",
        "published": true,
        "tags": "",
        "price": "100"
      }
    }
  })
};

或者,

var params = {
  "method": "POST",
  "headers": { "Authorization": "Basic " + Utilities.base64Encode(key + ":" + secret) },
  // "contentType": "application/json",
  "muteHttpExceptions": true,
  "payload": JSON.stringify({
    "products": {
      "product": {
        "body_html": "",
        "product_type": "JEWELLERY - Bracelets",
        "published_scope": "global",
        "title": "Burton Custom Freestyle 151",
        "vendor": storeName,
        "status": "active",
        "published": true,
        "tags": "",
        "price": "100"
      }
    }
  })
};

参考文献: