What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Delete files from themes after App/Uninstalled webhook is received

Delete files from themes after App/Uninstalled webhook is received

ShrutiM
Shopify Partner
15 0 2

When I receive an App/Uninstalled, one of the things I need to do is revert the changes that I have done in files "theme.liquid","search.liquid","cart-template.liquid","product-template.liquid" and there are two more files that I need to delete. But as we know that after App/Uninstalled the access_token becomes invalid. Now I am getting an Error 401, that the Token is Unauthorized. While this makes sense, how can I revert and delete files for a theme

Replies 3 (3)

Gavinator
Shopify Partner
1318 15 124

You can use a strategy of seeing if the scripttag your App previously added is still in play: https://www.shopify.com/partners/blog/add-code-from-your-app Coupled with the ability to use the Shopify CDN to proxy your scripts I'd say this is the best way to tackle it at this time.

HTH, Gavin.

www.bookthatapp.com
ShrutiM
Shopify Partner
15 0 2

Hi Gevin,

 

Thanks for sharing the information about script tag. Like I mentioned my changes include adding some piece of code in liquid file and add a new liquid and js file.

I was able to do the same by calling assets apis. Even when we use script tag we have to either manually/programmatically add some code in existing files. But once app is uninstalled script tag will be removed but the piece of code is that we added will still be there. Is there any other way to remove that.

 

Thanks and Regards

Vivek Solanki

Gavinator
Shopify Partner
1318 15 124

But once app is uninstalled script tag will be removed but the piece of code is that we added will still be there. Is there any other way to remove that.

No. Once your App is uninstalled you no longer have permission to access anything.

The only thing you can do is make sure the code you add checks if the script tag you added is still there:

{% if content_for_header contains ‘viveks-script’ %}
{% comment %}Put your code here. It will only run if the script tag you previously installed is still present.{% endcomment %}
{% endif %}

When your App is uninstalled the script tag will not be present, so your code will not run.

HTH, Gavin.

www.bookthatapp.com