我嘗試了很多,但仍然無法使用 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)
uj5u.com熱心網友回復:
在你的情況下,下面的修改怎么樣?
從:
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"
}
}
})
};
- 從“創建新產品”的檔案來看,我認為
"contentType": "application/json"可能不需要使用。
參考:
- 創建新產品
- fetch(url, params)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/346524.html
標籤:javascript 谷歌应用程序脚本 shopify-api
