"对象,参考不设定对象的一个实例"的错误在尝试更新的产品ShipStation的API

0

的问题

我有麻烦更新的产品在Shipstation.

我一直使用这2个链接查看如何我应该格式在响应:

https://www.shipstation.com/docs/api/products/update/ https://www.any-api.com/shipstation_com/shipstation_com/docs/Products/_products_productId_/PUT

我相信我下面是正确的,但我总是获得一个500错误信息,说"对象参考,不设置一个实例的对象"。

我已经使用得到的请求,以获得产品属性。 然后我更新的属性,需要加以改变,并将其储存在 data (这是一系列的对象)。 然后我用的是把要求发送的数据。

这是相关代码:

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)看起来像: 空值是什么,我收到从得到的请求。 我更喜欢那些属性留空。

{"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前做了一把请求? 我是什么丢失?

1

最好的答案

0

在你的脚本,如有关以下修改?

自:

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",
};

参考:

2021-11-24 00:30:32

不能相信它是这样一个简单的解决。 谢谢你这么多! 顺便说一句有效载荷在你的答案是拼写错误
oscark

@oscark谢谢你的回复。 我很高兴你的问题得到解决。 有关拼错,谢谢你检查它。 我要修改。 谢谢你,太。
Tanaike

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................