0
votes

I am trying to get a basic API request to create a product working for shopify but keep getting an error that I am missing a required parameter. (the only required parameter is title)

ERROR:

object(stdClass)#295 (1) { ["errors"]=> object(stdClass)#297 (1) { ["product"]=> string(37) "Required parameter missing or invalid" } }

Here is code

    $data = array();
    $data['product'] = array(
        'title' => 'Burton Custom Freestyle 151',
        'product_type' => 'Category',
        'published_scope' => 'web',
        'status' => 'active',
        'body_html' => '<strong>Good snowboard!</strong>',
    );

    $this->do_post('/admin/api/2020-10/products.json',$data);


private function do_post($end_point,$data)
{
    $ch = curl_init($this->base_url_api.$end_point);  
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
    $headers = array(  
        'X-Shopify-Access-Token: '.$this->api_code_token,                                                                                
    );
            
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
   $return = json_decode(curl_exec($ch)); 
   var_dump($return);
   return $return;
    
}
1

1 Answers

1
votes

It's best practice (IMO) to always include a header to specify the type of content you're sending. With curl that would be -H "Content-Type: application/json". Some API's even require charset=utf-8 (like the Slack API).

To investigate my initial hunch further, I found this page which may be of use: https://community.shopify.com/c/Shopify-APIs-SDKs/Required-parameter-missing-or-invalid-on-variant-update/td-p/317216