Examine updating API Asset collection.liquid using PUT method yielding 404 with cURL

I am trying to update collection.liquid using the Shopify API.
I am using below Shopify API wrapper with CodeIgniter,

Detect API

This wrapper uses cURL to call the API. I have used this library to build other Shopify apps and it works great with GET, POST methods . I first tried using the PUT method with it . and it gives me the cURL error given below
ERROR # 22: The requested url returned an error: 404 Not Found "

    protected function modify_asset($theme_id)
{

       $data = array(
            'API_KEY' => $this->config->item('shopify_api_key'),
            'API_SECRET' => $this->config->item('shopify_secret'),
            'SHOP_DOMAIN' => $this->session->userdata('shop_domain'),
            'ACCESS_TOKEN' => $this->session->userdata('access_token')
        );

        $this->load->library('shopify', $data);

        $fields = array(
            "asset" => array(

                "key" => "templates\/collection.liquid",
                "value" => "<p>We are busy updating the store for you and will be back within 10 hours.<\/p>"

            )
        );



        $args = array(

                 'URL' => '/admin/themes/163760333/assets.json',
                 'METHOD' => 'PUT',
                 'RETURNARRAY' => TRUE,
                 'DATA' => $fields
            );
        try{

            $modification_response = $this->shopify->call($args);
            return $modification_response;


        }
        catch(Exception $e){
            $modification_response = $e->getMessage();
            log_message('error','In Get Active Theme Id' . $modification_response);
            //redirect('/wrong/index');
            var_dump('In modification response ' . $modification_response);
            exit;
        }

}


}

      


Above is my function to implement the API call. You can see the cURL options and its implementation at the link below:
cURL options and the Shopify API call flow

Note. This request works fine on POSTMAN.

+3


source to share


1 answer


I just ran some tests on this code using the information you provided and was able to get a successful view after removing the backslash in $ fields ['asset'] ['key'] as per the example above.

So,

"key" => "templates\/collection.liquid",



becomes:

"key" => "templates/collection.liquid",

It looks like Shopify doesn't require slash skew in files that need to be escaped.

+1


source







All Articles