使用API​​创建订单的Bigcommerce提供“客户端错误(400):字段'产品'无效。”

时间:2016-06-07 07:07:49

标签: api bigcommerce

我正在尝试使用API​​创建订单。

   $product_id = 111;

$order_data = array(
'customer_id'=>0,
'status_id' => 1,
'products'=>array(
'product_id'=>(int)$product_id,
'quantity'=>1
),
'billing_address'=>array(
 "zip"=> "78757",
 "city"=> "Austin",
 "email"=> "kane@test.com",
 "state"=> "Gold Coast",
 "country"=> "Australia",
 "street_1"=> "12345 W Anderson Ln",
 "last_name"=> "Damio",
 "first_name"=> "Kane",
 "country_iso2"=> "AU"
 ),
);


Bigcommerce::failOnError();

try {
    $order = Bigcommerce::createOrder($order_data);
    print_r($order);

} catch(Bigcommerce\Api\Error $error) {
    echo $error->getCode();
    echo $error->getMessage();
}

我很确定我已经正确地遵循了文档,我得到了回复

致命错误:未捕获的客户端错误(400):字段“产品”无效。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

我想出了自己大声笑,我只需要在数组中添加产品术语

$order_data = array(
'customer_id'=>0,
'status_id' => 1,
'products'=>array(
'product'=>array(
'product_id'=>(int)$product_id,
'quantity'=>1
)
),
'billing_address'=>array(
 "zip"=> "78757",
 "city"=> "Austin",
 "email"=> "kane@test.com",
 "state"=> "Gold Coast",
 "country"=> "Australia",
 "street_1"=> "12345 W Anderson Ln",
 "last_name"=> "Damio",
 "first_name"=> "Kane",
 "country_iso2"=> "AU"
 ),
);

我希望它有所帮助。