Home > Mobile >  Shopify PUT code into layout/theme with assets rest api
Shopify PUT code into layout/theme with assets rest api

Time:11-18

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>"
    ]
]);

CodePudding user response:

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);

CodePudding user response:

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);
  • Related