How to apply shopify extension snippet to theme with API

Topic summary

A developer needed to programmatically apply a theme app extension snippet to a Shopify store’s main theme using the API, specifically wanting to add code to the theme.liquid file.

Initial Challenge:

  • Created and published a theme app extension with a snippet
  • Unclear how to apply it to the store’s main theme via API
  • Standard documentation about adding snippets to the snippets directory wasn’t applicable to app extensions

Solution Found:
The developer resolved the issue by:

  • Creating a block with "target": "body" in the schema
  • Deploying the extension using Shopify CLI
  • Using deep linking to enable the block
  • Having the customer/merchant activate the block via the deep link

Code Example Provided:
A liquid block file with schema containing name, target (body), javascript file reference, and settings array.

Another user requested more detailed explanation of the solution process for future reference.

Summarized with AI on November 17. AI used: claude-sonnet-4-5-20250929.

Hi, I am trying to set up a theme app extension,
I created an extension and published it with the snippet.
Now I want to apply this snippet to the store’s main theme. But I don’t understand how to do it.
Snippet should be added to theme.liquid file.
I can change theme assets with API to include my code, but I don’t understand how to do it with app extensions.

I read this doc, but its unclear https://shopify.dev/docs/apps/online-store/theme-app-extensions/update

I need exactly this, but it’s unclear how to do it with the app extension

For example, apps often require the following to integrate with online stores:> > - Adding snippets to the snippets directory of a published theme, which are then added to a page by modifying Liquid layout, template, or section files.

How to apply code block or snippet to the theme.

OK I found the answer, I need to create block with “target”: “body”,

Hey, I wanted to follow up on your recent response regarding the code issue. While I appreciate your input, it would be immensely helpful if you could provide a more detailed explanation of your solution. Could you please expand on the steps and thought process behind your answer, including any relevant code snippets or considerations? This would greatly enhance my understanding and benefit others who may encounter a similar problem.

You need to create a block as described in documentation
for example
your-block.liquid

{% schema %}
{
“name”: “Block name”,
“target”: “body”,
“javascript”: “yourjavascriptfile.js”,
“settings”:
}
{% endschema %}

Then you can deploy this with Shopify cli
after that, you need to use a deep link - and ask the customer/to enable your block using that deep link.
https://shopify.dev/docs/apps/online-store/theme-app-extensions/extensions-framework#deep-linking