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.

Re: Delete metaobject on App uninstall

Delete metaobject on App uninstall

Lucifer4
Shopify Partner
8 0 3

Hi everyone,

 

I create app based on shopify-app-remix. It creates definitions and meta objects that I would like to delete before uninstalling the app. I tried to use webhooks but unfortunately I don't have the option to delete them using GraphQL Admin API ( gets a 401 error).

Is there any way to remove app-created meta-objects and their definitions from the store?

 

Replies 6 (6)

SBD_
Shopify Staff
1831 273 422

Hey @Lucifer4 

 

Unfortunately not. Right now cleanup includes deleting any registered webhooks, script tags, and Shopify admin links. Definitions and meta objects remain.

Scott | Developer Advocate @ Shopify 

Lucifer4
Shopify Partner
8 0 3

I understand, but in my case the meta-objects hold the application data and its settings. Is this the wrong approach?

SBD_
Shopify Staff
1831 273 422

Hey @Lucifer4 

 

I guess it's all tradeoffs - depending on your use case, consider using private metafields or keeping settings in your database.

Scott | Developer Advocate @ Shopify 

ntlan63
Shopify Partner
2 0 1

I ran into the same problem and I found out the solution. So let's try if anyone needs it. You can save the ID of the metaobject definition in a database or retrieve it by type and delete the metaobject Definition by ID. You can write the code in the file "webhook.tsx" in the topic case - "APP_UNINSTALLED".

 
enucar
Shopify Partner
9 0 0

Hi Ntlan63. I have also tried this, but the webhook behaves strangely and doesn't remove the metafield. It's not even retrieving the ID, even though the Query works in the GraphiQL playground. Can you show me your example code, please? Here is mine.

 

enucar_0-1716996603755.png

The delete mutation is below this query, but it's not necessary to post it here since the query is not working.

 

ntlan63
Shopify Partner
2 0 1

Sorry. It was my mistake to draw conclusions based on just 1-2 fortunate instances. I suspect that the access token expires right after the app is uninstalled, leaving insufficient time to execute a query.