我在 Shipstation 中更新產品時遇到問題。
我一直在使用這兩個鏈接來查看我應該如何格式化回應:
https://www.shipstation.com/docs/api/products/update/ https://www.any-api.com/shipstation_com/shipstation_com/docs/Products/_products_productId_/PUT
我相信我正確地遵循它,但我總是收到一條 500 錯誤訊息,指出“物件參考未設定為物件的實體”。
我一直在使用 GET 請求來獲取產品的屬性。然后我更新需要更改的屬性,并將其存盤在data(這是一個物件陣列)中。然后我使用 PUT 請求發送資料。
這是相關代碼:
function updateProducts(authString, data) {
var baseProductUrl = `https://ssapi.shipstation.com/products/`;
for(var d = 0; d < data.products.length; d ) { //for each product I'd like to update...
var raw = data.products[d];
raw = JSON.stringify(raw);
var requestOptions = {
method: 'PUT',
headers: {
"Authorization": `Basic ${authString}`,
"Content-Type": `application/json`,
},
body: raw,
redirect: 'follow'
};
var productUrl = `${baseProductUrl}${data.products[d].productId}`;
UrlFetchApp.fetch(productUrl, requestOptions);
}
}
這就是raw(我發送到 ShipStation 的資料)的樣子:空值就是我從 GET 請求中接收到的值。我希望這些屬性保持為空。
{"aliases":null,
"productId":123456789, //placeholder
"sku":"sku", //placeholder
"name":"UV Bulb - 1GPM - 10\"",
"price":19.99,
"defaultCost":null,
"length":2,
"width":2,
"height":13,
"weightOz":7,
"internalNotes":null,
"fulfillmentSku":null,
"active":true,
"productCategory":null,
"productType":null,
"warehouseLocation":null,
"defaultCarrierCode":null,
"defaultServiceCode":null,
"defaultPackageCode":null,
"defaultIntlCarrierCode":null,
"defaultIntlServiceCode":null,
"defaultIntlPackageCode":null,
"defaultConfirmation":null,
"defaultIntlConfirmation":null,
"customsDescription":"UV Bulb - 1GPM - 10\"", //attribute I'd like to update
"customsValue":9.99, //attribute I'd like to update
"customsTariffNo":null,
"customsCountryCode":"US",
"noCustoms":null,
"tags":null}
那么有沒有人有任何提示,或者有沒有人之前使用過 ShipStation 的 API 并完成 PUT 請求?我錯過了什么?
uj5u.com熱心網友回復:
在您的腳本中,以下修改如何?
從:
var requestOptions = {
method: 'PUT',
headers: {
"Authorization": `Basic ${authString}`,
"Content-Type": `application/json`,
},
body: raw,
redirect: 'follow'
};
到:
var requestOptions = {
method: 'PUT',
headers: {
"Authorization": `Basic ${authString}`,
},
payload: raw,
contentType: "application/json",
};
參考:
- 獲取(網址,引數)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/367954.html
標籤:javascript 接口 谷歌应用程序脚本 电子商务
