Hello, so when I initially had problems with the put, this was my code.
let options = (httpMethod, body) => {
return {
method: httpMethod,
headers: {
'Content-Type': "application/json",
'api-auth-accountid': "...",
'api-auth-applicationkey': "..."
},
'body': body
}
};
let putUrl = "https://inventory.dearsystems.com/ExternalApi/v2/product";
let checkProductSupplierList = async (prod) => {
// get supplierID to add to product suppliers list
let linkedID = suppliers["linkedRecordIds"][0];
let supplier = supplierRecords.getRecord(linkedID);
let supplierID = supplier.getCellValue("SupplierID")[0];
if (prod["Suppliers"].length === 0) {
prod["Suppliers"] = [{ "SupplierID": supplierID, "DropShip": true }];
prod["DropShipMode"] = "Optional Drop Ship";
let putResults = await remoteFetchAsync(putUrl, options("put", JSON.stringify(prod)));
let putObject = await putResults.json();
console.log("put response", putObject)
}
for (let product of lines) {
if (product["SKU"] === productSku) {
let prod = await getProduct(product["ProductID"]);
prod = prod['Products'][0];
checkProductSupplierList(prod)
}
product["DropShip"] = true;
break;
}
}
What worked was this…
let checkProductSupplierList = (prod) => {
let linkedID = suppliers["linkedRecordIds"][0];
let supplier = supplierRecords.getRecord(linkedID);
let supplierID = supplier.getCellValue("SupplierID")[0];
if (prod["Suppliers"].length === 0) {
prod["Suppliers"] = [{ "SupplierID": supplierID, "DropShip": true }];
prod["DropShipMode"] = "Optional Drop Ship";
return true;
}
return false;
}
for (let product of lines) {
if (product["SKU"] === productSku) {
let prod = await getProduct(product["ProductID"]);
prod = prod['Products'][0];
let putBool = checkProductSupplierList(prod);
if (putBool) {
let putUrl = "https://inventory.dearsystems.com/ExternalApi/v2/product";
let putResults = await remoteFetchAsync(putUrl, options("put", JSON.stringify(prod)));
let jsonObject = await putResults.json();
output.inspect(jsonObject);
}
product["DropShip"] = true;
break;
}
}