Ho problemi con l'aggiornamento di un prodotto in Shipstation.
Io sono stato con questi 2 link per vedere come devo formattare la risposta:
https://www.shipstation.com/docs/api/products/update/ https://www.any-api.com/shipstation_com/shipstation_com/docs/Products/_products_productId_/PUT
Credo che sto seguendo è corretta, ma ricevo sempre un messaggio di errore 500 dicendo: "riferimento a un Oggetto non impostato su un'istanza di oggetto".
Ho usato la richiesta GET per ottenere un prodotto di attributi.
Quindi posso aggiornare gli attributi che devono essere cambiati, e conservarla in data
(che è un array di oggetti). Allora io uso la richiesta PUT per inviare i dati.
Questo è il codice in questione:
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);
}
}
Questo è ciò che raw
(i dati sono di invio di ShipStation), assomiglia a questo:
I valori null sono semplicemente ciò che ricevo dalla richiesta GET. Io preferisco quelli attributi di rimanere vuota.
{"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}
Così qualcuno ha qualche dritta, o qualcuno ha usato ShipStation API di prima e fatto una richiesta PUT? Che cosa mi manca?