我正在尝试使用API为订单创建履行,此履行应包含跟踪编号。我正在通过请求传递跟踪号码,请求显示成功(订单在管理员中正确履行)。但是,我传递的跟踪号码永远不存在。
我不包括订单项(以履行订单中的所有商品),不过我已经尝试过两种方式(一次只完成一件商品)
//$id, $key and $password are set previously
$endpoint = "https://{$key}:{$password}@mystore.shopify.com/admin/orders/{$id}/fulfillments.json";
$fulfillment = array(
'fulfillment' => array(
'tracking_number' => '12345'
)
);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fulfillment));
res = curl_exec($ch);
运行上面的代码后,$ res包含类似的内容:
{"fulfillment":{"created_at":"2012-10-22T16:57:53-04:00","id":69428396,"order_id":143675378,"service":"manual","status":"success","tracking_company":null,"tracking_number":null,"tracking_url":"http://www.google.com/search?q=","updated_at":"2012-10-22T16:57:53-04:00","receipt":{},"line_items":[{"fulfillment_service":"manual","fulfillment_status":"fulfilled","grams":0,"id":233975006,"price":"19.00","product_id":108718266,"quantity":1,"requires_shipping":true,"sku":"","title":"Profound grid-enabled intranet","variant_id":248446746,"variant_title":null,"vendor":"Shopify","name":"Profound grid-enabled intranet","variant_inventory_management":null,"properties":[]},{"fulfillment_service":"manual","fulfillment_status":"fulfilled","grams":0,"id":233975008,"price":"19.00","product_id":108718276,"quantity":2,"requires_shipping":true,"sku":"","title":"Operative multi-tasking task-force","variant_id":248446754,"variant_title":null,"vendor":"Shopify","name":"Operative multi-tasking task-force","variant_inventory_management":null,"properties":[]}]}}
您可以在该回复中看到,订单项的履行状态设置为已完成(正确),但tracking_number为空(不正确)。
非常感谢任何帮助!
答案 0 :(得分:1)
需要为请求指定内容类型。
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json');