Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Cannot upload asset to Layout folder - 422 error

Solved

Cannot upload asset to Layout folder - 422 error

FootsieNG
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.

Accepted Solution (1)
FootsieNG
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>`
}
}

View solution in original post

Replies 3 (3)

Gregarican
Shopify Partner
1033 86 293

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?

FootsieNG
Tourist
7 1 1

Thanks Greg but the problem still persist.

FootsieNG
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>`
}
}