skip to Main Content

I am trying to post into my theme.liquid file, but it gives a 404 error, i can find the asset fine with a get method, but the post does not work, this is my code any suggestions?

$response = $shop->api()->rest('POST', '/admin/api/202110/themes/128946634999/assets.json', 
[ "asset" => [
"key" => "layout/theme.liquid",
"value" => "<p>This is a test API upload.</p>"
    ]
]);

2

Answers


  1. Chosen as BEST ANSWER

    I figured out how to insert into the layout/theme.liquid file, i found that you need to have both the {{ content_for_header }} and {{ content_for_layout }} in the string before shopify recognizes it.

                        
    $param = [
       'asset'=>[
       "key" => "layout/theme.liquid",
       "value" => "{{ content_for_header }} TEST {{ content_for_layout }}"
       ]
    ];
                                
    $response = $shop->api()->rest('put','/admin/api/2021-10/themes/128946634999/assets.json',$param);
    

  2. You can try this code

    $param = [
        'asset'=>[
            "key" => "layout/theme.liquid",
            "value" => "<p>This is a test API upload.</p>"
        ]
    ];
    
    $response = $shop->api()->rest('put','/admin/api/2021-10/themes/128946634999/assets.json',$param);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search