1

我正在尝试使用 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 为空(不正确)。

任何帮助是极大的赞赏!

4

1 回答 1

1

需要为请求指定内容类型。

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json');
于 2012-11-18T22:10:30.390 回答