
Here is the sample code to create a new Shopify product using PHP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$apiKey = "API_KEY"; $pwd = "API_PASSWORD"; $baseUrl = "https://".$apiKey .":". $pwd ."@SHOPIFY_SHOP_URL"; $product = array('title' => 'My New Product', 'body_html' => 'My New Product Description', 'vendor'=> 'My Product Vendor', 'product_type'=> 'My Product Type', 'variants' => array( array('option1' => 'Default', 'price' => '100.00', 'sku' => 'ABC123', 'inventory_quantity'=> '999', 'inventory_management' => 'shopify', 'taxable' => true, 'requires_shipping' => true ) ) ); $ch = curl_init($baseUrl.'/admin/products.json'); //set the url $data_string = json_encode(array('product'=>$product)); //encode the product as json curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //specify this as a POST curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); //set the POST string curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //specify return value as string curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($data_string)) ); //specify that this is a JSON call echo $server_output = curl_exec ($ch); //get server output if you wish to error handle / debug curl_close ($ch); //close the connection |