I am attempting to generate orders on my BigCommerce store using the BigCommerce API. I am using the code below to accomplish this. I am able to ping BigCommerce just fine and I get no errors in the php code. The problem is that it doesn't ever generate the order on my Bigcommerce store.
require('vendor/autoload.php');
use Bigcommerce\Api\Client as Bigcommerce;
Bigcommerce::configure(array(
'store_url' => 'https://my-store.bigcommerce.com/',
'username' => 'admin',
'api_key' => 'XXXXXX'
));
$ping = Bigcommerce::getTime();
if ($ping){ echo $ping->format('H:i:s');}
$createFields = array(
"customer_id" => 0,
"date_created" => $today,
"status_id" => 1,
"billing_address" => array(
"first_name" => "Trisha",
"last_name" => "McLaughlin",
"company" => "",
"street_1" => "12345 W Anderson Ln",
"street_2" => "",
"city" => "Austin",
"state" => "Texas",
"zip" => "78757",
"country" => "United States",
"country_iso2" => "US",
"phone" => "",
"email" => "elsie@example.com"),
"shipping_addresses" => array(
"first_name" => "Trisha",
"last_name" => "McLaughlin",
"company" => "",
"street_1" => "12345 W Anderson Ln",
"street_2" => "",
"city" => "Austin",
"state" => "Texas",
"zip" => "78757",
"country" => "United States",
"country_iso2" => "US",
"phone" => "",
"email" => "elsie@example.com"),
"external_source" => "POS",
"products" => array(
"product_id" => "90",
"quantity" => "1"));
print_r(Bigcommerce::createOrder($createFields));
What am I missing?
Am I using the BigCommerce API incorrectly?
Any help on figuring out why my code isn't generating orders on my Bigcommerce store would be awesome!
Try removing the quotes from the "quantity" parameter in the products array. It's expecting an int instead of a string.
products'=>array(
'product'=>array(
'product_id'=>90
'quantity'=>1
The products
property needs to be a nested array, where each individual product within the parent products
array must exist as its own array:
"products" => array(
0 => array(
"product_id" => int,
"quantity" => int
),
1 => array(
"product_id" => int,
"quantity" => int,
)
),
Set Your Array Like This:
$createFields=Array(
"customer_id" => 0,
"status_id"=> 10,
"billing_address"=> [
"first_name"=> "Trisha",
"last_name"=> "McLaughlin",
"company"=> "",
"street_1"=> "12345 W Anderson Ln",
"street_2"=> "",
"city"=> "Austin",
"state"=> "Texas",
"zip"=> "78757",
"country"=> "United States",
"country_iso2"=> "US",
"phone"=> "",
"email"=> "a@example.com"
],
"shipping_addresses"=>[
[
"first_name"=> "Trisha",
"last_name"=> "McLaughlin",
"company"=> "Acme Pty Ltd",
"street_1"=> "566 Sussex St",
"street_2"=> "",
"city"=> "Austin",
"state"=> "Texas",
"zip"=> "78757",
"country"=> "United States",
"country_iso2"=> "US",
"phone"=> "",
"email"=> "a@example.com"
]],
"products"=>[
[
"product_id"=> 90,
"quantity"=>1,
// "name"=> "data",
],
],
"external_source"=> "POS"
);