Cannot upload asset to Layout folder - 422 error

Solved
Highlighted
Tourist
7 1 1

I'm using the the admin API to make a restful PUT request to upload some file to theme folders.

I can successfully upload files to any folder other that the 'Layout' folder, which gives a 422 error. Uploading to assets, templates sections etc works perfectly. 

 

I'm using the below PUT request and payload.

PUT /admin/api/2020-04/themes/{themeID}/assets.json
{
"asset": {
"key": "layout/themes-test.liquid",
"value": "The HTML FOR THEME.LIQUID"
}
}


Does the Layout folder require some special permissions for upload?

Thanks in advance.

0 Likes
Highlighted
Shopify Partner
520 38 109

Perhaps what's being provided in the "value":  isn't being received correctly? Maybe try something simple in that property to see if it works.

 

Such as:

<p>This is a test API upload.</p>

 

Does this result in the 422 HTTP response as well?

0 Likes
Tourist
7 1 1

Thanks Greg but the problem still persist.

0 Likes
Highlighted
Tourist
7 1 1

This is an accepted solution.

Found the problem. Shopify expects the following to be present within the head and body tags respectively:

{{content_for_header}} and {{content_for_layout}}

Injecting the following satisfies the above requirement and works!

{
"asset": {
"key": `layout/theme-test.liquid`,
"value": `<head>{{content_for_header}}</head><body>{{content_for_layout}}</body>`
}
}
1 Like