user399883
user399883

Reputation: 253

Bigcommerce create order using API gives "Client Error (400): The field 'products' is invalid."

I am trying to create a order with 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"=> "[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();
}

I am pretty sure i have followed the documentation correctly and i get this in response

Fatal error: Uncaught Client Error (400): The field 'products' is invalid. Any help will be much appreciated.

Upvotes: 0

Views: 337

Answers (1)

user399883
user399883

Reputation: 253

I figured out myself lol, I just had to add the product term in the array

$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"
 ),
);

i hope it helps someone.

Upvotes: 2

Related Questions