"อ้างอิงถึงวัตถุงไม่ถูกตั้งค่าให้เป็นตัวอย่างขอเป็นวัตถุ"เกิดข้อผิดพลาดตอนที่พยายามที่จะปรับปรุงเป็นผลิตภัณฑ์กับ 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)ดูเหมือนว่า: ที่โพรโทคอล aimcomment ค่าเป็นแค่สิ่งที่ฉันได้รับจากที่ได้อยากขอให้ช่วยอะไรหน่อย ฉันคงอยากจะให้พวกคุณลักษณะอยู่ว่างเปล่า

{"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

ไม่อยากเชื่อว่ามันเป็นเรื่องง่ายจะจัดการกับมัน ขอบคุณมาก! btw ยมหัวรบของนายให้อยู่ในคำตอบของคุณคือคำที่สะกดผิด
oscark

@oscark ขอบคุณสำหรับ replying. ฉันดีใจที่ปัญหาของคุณถูกแก้ไขเรียบร้อยแล้ว เรื่อง misspell ขอบคุณสำหรับตรวจมัน. ฉันต้องการจะแก้ไขมัน ขอบคุณเหมือนกัน
Tanaike

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่