A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
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.
Solved! Go to the solution
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>` } }
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?
Thanks Greg but the problem still persist.
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>` } }