通过ShipStation API更新订单重量

时间:2015-04-07 14:01:24

标签: api

我正在构建一个更新订单重量的ShipStation API集成。它适用于属于本机ShipStation商店的订单(在我的情况下称为“手动订单”)。

但是,对于属于Etsy商店的订单,重量更新失败(这些订单在Etsy中创建并由ShipStation导入)。我已尝试使用additionalOptions和没有(无论如何都标记为可选)。这是我的要求:

{
weight:{
  value:'39',
  units:'ounces'
},
orderKey:'1009247505',
orderNumber:'1009247505',
orderDate:'2015-04-02T18:00:50.0000000',
orderStatus:'awaiting_shipment',
billTo:{
  name:'Sophia Sun',
  company:null,
  street1:null,
  street2:null,
  street3:null,
  city:null,
  state:null,
  postalCode:null,
  country:null,
  phone:null,
  residential:null,
  addressVerified:null
},
shipTo:{
  name:'Sophia Sun',
  company:null,
  street1:'9851 NE 16TH ST',
  street2:'',
  street3:null,
  city:'BELLEVUE',
  state:'WA',
  postalCode:'98004-3426',
  country:'US',
  phone:null,
  residential:true,
  addressVerified:'Address validated successfully'
},
advancedOptions:{
  warehouseId:19400,
  nonMachinable:false,
  saturdayDelivery:false,
  containsAlcohol:false,
  mergedOrSplit:false,
  parentId:null,
  storeId:29420,
  customField1:null,
  customField2:null,
  customField3:null,
  source:null,
  billToParty:null,
  billToAccount:null,
  billToPostalCode:null,
  billToCountryCode:null
},
items:[
  {
    orderItemId:180328770,
    lineItemKey:'1018978111',
    sku:'173914528',
    name:'12 Sizes Available: Indigo Decorative Throw Zipper Pillow Cover 16x16 18x18 20x20 22x22 inches',
    imageUrl:'https://img1.etsystatic.com/036/0/7621433/il_fullxfull.544582063_aw56.jpg',
    weight:null,
    quantity:1,
    unitPrice:22,
    warehouseLocation:null,
    options:[
      {
        name:'Size',
        value:'20x20 inches'
      },
      {
        name:'Fabric',
        value:'Susanna'
      }
    ],
    productId:15935328,
    fulfillmentSku:null
  },
  {
    orderItemId:180328769,
    lineItemKey:'1018978113',
    sku:'174027396',
    name:'One Taupe, Blue, Indigo, Grey Decorative Throw Pillow Cover 8 Fabrics and 7 Sizes Grey Blue Tan Accent Pillow Cover',
    imageUrl:'https://img0.etsystatic.com/041/0/7621433/il_fullxfull.544517672_fdto.jpg',
    weight:null,
    quantity:1,
    unitPrice:22,
    warehouseLocation:null,
    options:[
      {
        name:'Size',
        value:'20x20 inches'
      },
      {
        name:'Fabric',
        value:'Honeycomb'
      }
    ],
    productId:16124487,
    fulfillmentSku:null
  },
  {
    orderItemId:180328768,
    lineItemKey:'1019027922',
    sku:'173914528',
    name:'12 Sizes Available: Indigo Decorative Throw Zipper Pillow Cover 16x16 18x18 20x20 22x22 inches',
    imageUrl:'https://img1.etsystatic.com/036/0/7621433/il_fullxfull.544582063_aw56.jpg',
    weight:null,
    quantity:1,
    unitPrice:22,
    warehouseLocation:null,
    options:[
      {
        name:'Size',
        value:'20x20 inches'
      },
      {
        name:'Fabric',
        value:'Grey Cat\'s Eye'
      }
    ],
    productId:15935328,
    fulfillmentSku:null
  },
  {
    orderItemId:180328767,
    lineItemKey:'1019027924',
    sku:'173914528',
    name:'12 Sizes Available: Indigo Decorative Throw Zipper Pillow Cover 16x16 18x18 20x20 22x22 inches',
    imageUrl:'https://img1.etsystatic.com/036/0/7621433/il_fullxfull.544582063_aw56.jpg',
    weight:null,
    quantity:1,
    unitPrice:22,
    warehouseLocation:null,
    options:[
      {
        name:'Size',
        value:'20x20 inches'
      },
      {
        name:'Fabric',
        value:'Madison'
      }
    ],
    productId:15935328,
    fulfillmentSku:null
  }
]
}

这是响应中的堆栈跟踪:

{
  "Message": "An error has occurred.",
  "ExceptionMessage": "Object reference not set to an instance of an object.",
  "ExceptionType": "System.NullReferenceException",
  "StackTrace": "   at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__b.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__21`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()"
}

那么,通过ShipStation API更新权重的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

我正在通过python进行操作,将字典作为数据传递,并遇到相同的错误。对我来说,解决方案是在发布到shipstation时传递具有适当内容类型的json编码字符串。 代码:

headers = {'Content-type': 'application/x = requests.post('https://ssapi.shipstation.com/orders/createorder', data=json.dumps(order_data),
                          auth=HTTPBasicAuth('user', 'password'),
                          headers=headers)