POST product with Shopify returns 406 error

Viewed 466
        $url = "https://key:password@garageprints.myshopify.com/admin/api/2019-10/products/product.json";
        $authentication = "key:password";
        $authentication = base64_encode($authentication);

        $postData = array(
            'product' => [
                'title' => 'Burton Custom Freestyle 151',
                'body_html' => 'Good snowboard!',
                'vendor' => 'Burton',
                'product_type' => 'Snowboard',
                'tags' => 'Barnes & Noble, John\'s Fav, Big Air'
            ]
        );

        $postData = json_encode($postData);

        // Setup cURL
        $ch = curl_init($url);
        curl_setopt_array($ch, array(
            CURLOPT_POST => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_HEADER => TRUE,
            CURLOPT_HTTPHEADER => array(
                'Authorization: Basic ' . $authentication,
                'Content-Type: application/json'
            ),
            CURLOPT_POSTFIELDS => $postData
        ));

        // Send the request
        $response = curl_exec($ch);

        return ($response);

Trying to send a post request with php code in Laravel returns an error. I know that it is not necessary to send the authentication through the header but I included it to show that I tried that. I am kinda new to curl with php so I am not very familiar with curl_setopt, I might be missing something obvious. I am using the example json file provided in Shopify api documentation.

Response in chrome, in the incoming connections Shopify returns a 200 code but the response variable being returned by php shows a 406 error

Also I am sending the same request with postman but I only get the 200 ok status and a continue button with a link, yet sending the same request with PHP does not return this html file Postman

0 Answers
Related