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 285

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