How to create a file with content using Shopify API

Topic summary

Problem: Creating a Shopify theme snippet via the Admin API works for short content (2–3 lines) but fails when the snippet contains a form or JavaScript.

Implementation details: Using Laravel with the Osiset package to call PUT /admin/api/2022-10/themes/{theme_id}/assets.json. Payload sets key “snippets/contact-form.liquid” and value to the rendered Blade view (view(‘contact-form’)->render()).

Symptoms: No on-screen error; the page is blank. After some time, browser console shows error messages (an image is attached, but the specific error text isn’t provided).

Context/terms: “Snippet” is a Liquid template file within a Shopify theme. Osiset is a Laravel package for Shopify app integration. The Assets API endpoint manages theme files (e.g., Liquid, JS, CSS) by key and value.

Status: No resolution or confirmed cause yet. The thread seeks help identifying why the API call fails with more complex content.

Open questions: What error is shown in the console? Are there content, encoding, or payload constraints causing the asset creation to fail?

Summarized with AI on February 8. AI used: gpt-5.

I am trying to create a snippet file after the app is installed. I am using Osiset package of laravel to run the api. Now the issue is when file have 2-3 lines code then using API file get created and if the file have a form or javascript code then it is not creating.

Here is the code I am using to create a file:

$param = [
    'asset'=>[
    "key" => "snippets/contact-form.liquid",
    "value" => view('contact-form')->render()
    ]
];

$request2 = $shop->api()->rest('PUT', '/admin/api/2022-10/themes/'.$request['body']['container']['themes'][0]['id'].'/assets.json',$param);
echo "

";print_r($request2);echo "


";

No error/waring appears on the screen. All I see is the blank screen. But in the console after some time I saw an error messages

Please help me get this fixed.

Thanks