Cleanup after uninstalling the shopify app

Topic summary

App uninstall cleanup relies on a stable shop identifier, but the Admin API cannot be queried during the uninstall webhook because the access token is revoked immediately. The goal is to delete DB records by shop ID rather than by a potentially changeable domain.

Suggested approach: use the x-shopify-shop-domain header in the uninstall webhook. It represents the shop’s myshopify.com domain, which is considered immutable and distinct from the public-facing storefront domain.

Open question: the poster observes the header value appears identical to the storefront domain and asks if it would change when the storefront domain changes. They currently store the shop’s GraphQL ID (gid://shopify/Shop/) obtained via a shop query.

Technical notes: webhook = server callback on app uninstall; Admin API/GraphQL = Shopify’s admin interface for querying shop data; myshopify domain = internal, typically fixed; storefront domain = public, configurable.

Status: no final confirmation provided on the header’s immutability vs storefront domain. Action under consideration is using x-shopify-shop-domain for cleanup if it is indeed immutable.

Summarized with AI on December 19. AI used: gpt-5.

After uninstalling the app the uninstalled webhook is triggered so that I can cleanup the user data in my database.
But Iam cleaning up the DB based on shop’s ID not the domain because domain can be changed , so to get the shop’s ID I have to query the admin API but thats the issue after uninstalling the access token has been revoked immediately.
Any alternate solution would be helpful.

The domain sent in the “x-shopify-shop-domain” header should be the myshopify shop ID, which cannot be changed, so you should be fine to use that. This is different from the public facing domain the shop can configure and change.

Thanks for the reply but the value of this header x-shopify-shop-domain seems to same as the shop front store domain , suppose if anyone changed the domain so this also be changed or not ?

also I saving the shop ID which looks like this : gid://shopify/Shop/
I got this ID by querying

let response = await admin.graphql(
    `query {
            shop {
                name
                email
                id
                url
            }
        }`,
  );