Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hi all,
I'm developing an app which create metafields in the Shop scope. I would like to delete these metafields when the app is uninstalled.
I am able to get the list of the metafields in the app/uninstall webhook via this configuration:
In config/initializers/shopify_app.rb:
config.webhooks = [
{ topic: "app/uninstalled", address: "http://mywebsite/webhooks/app_uninstalled", format: "json", "metafield_namespaces": [ "myappnamespace"] },
]
Then i'm lopping over my metafields, and try to delete them one by them (as they are no bulk delete yet):
In app/jobs/app_uninstalled_job.rb:
class AppUninstalledJob < ActiveJob::Base
def perform(shop_domain:, webhook:)
shop = Shop.find_by(shopify_domain: shop_domain)
if shop.nil?
logger.error("#{self.class} failed: cannot find shop with domain '#{shop_domain}'")
return
end
shop.delete()
webhook[:metafields].each { |meta|
shop.with_shopify_session do
ShopifyAPI::Metafield.delete(meta["id"])
end
}
end
end
But I get a 403 error when i'm calling the API to delete them.
I wonder if we still have access to the shop when this webhook is called.
Is there any option to do this ?
Thanks
Solved! Go to the solution
This is an accepted solution.
Is there any option to do this ?
No. The workaround is to conditionally render your snippet content as described here: https://www.shopify.com.au/partners/blog/add-code-from-your-app (see the "Option Two" section).
HTH, Gavin.
Hi Lestt,
I also have this problem with my app. I've made a post about it: https://community.shopify.com/c/Shopify-APIs-SDKs/App-uninstalled-hook-cannot-use-access-token/m-p/1...
This is very unfortunate that Shopify doesn't seem to allow use of the access token the moment the app is uninstalled. In my case it's quite an issue because I need to perform a breif cleanup of an edited theme file 😕
Let me know if you find any updates or solution to this. I hope Shopify can allow the access token to be used briefly after app uninstall.
@Ari9 Thank you very much for your quick answer, but it does not helped me in my use case.
Hi @Lestt – my names Strat, a FED on the Metafields team 👋
I'm a little late to the party here. I understand you'd like to remove metafields after an app has been deleted. We don't have a great solution for this just yet. As you've noted, apps no longer have permissions to edit a shop once merchants decide to delete the app. I understand how that can be frustrating when you want to clean up your data. Shopify cannot provide access after merchants have decided to revoke it – we need to respect that decision.
As a result, we don't provide options for deleting resources after an app has been removed, but you do have some options:
I hope that's helpful moving forward!
To learn more visit the Shopify Help Center or the Community Blog.
This is an accepted solution.
Is there any option to do this ?
No. The workaround is to conditionally render your snippet content as described here: https://www.shopify.com.au/partners/blog/add-code-from-your-app (see the "Option Two" section).
HTH, Gavin.