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:
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.
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.
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:
Similarly, you can use App Extensions to securely surface your app’s functionality on a merchant’s online store. If your app is uninstalled, the section is then removed from themes without further intervention.
Outside of a theme, you can scope your app using Private metafields. Private metafields are only accessible to the app that created them, and they’re removed when the app is uninstalled. They’re a great option for creating settings in your app that can disable functionality once apps are deleted.