2016-06-07 50 views
0

我正在嘗試使用API​​創建訂單。Bigcommerce使用API​​創建訂單時出現「客戶端錯誤(400):字段'產品'無效。」

$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"=> "[email protected]", 
"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

我想通了,自己笑,我不得不添加陣列

$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"=> "[email protected]", 
"state"=> "Gold Coast", 
"country"=> "Australia", 
"street_1"=> "12345 W Anderson Ln", 
"last_name"=> "Damio", 
"first_name"=> "Kane", 
"country_iso2"=> "AU" 
), 
); 

我希望它可以幫助別人的乘積項。

相關問題