Shopify Python API Delete A Customer Metafield

- 1 answer

Is there a way to use the Shopify Python API to DELETE a metafield by ID or value?

Couldn't find a thing in the documentation

This is what I tried:




This is the method I just found out, I cycle through the entire product catalog (I think it could work with other resources too), then through each metafield until I find the metafield I want. Then I call metafield.destroy(). Like this:

for product in products:
    for metafield in product.metafields():
        if metafield.namespace == "global":

Originally I was working to do product.delete(metafield) but I kept getting a 406 error that I'm not sure how to resolve yet.

Note that I am fine destroying my metafields this way because each metafield I use (to this point) is a unique product identifier, and not shared by any other resource and so destroying the entire metafield would have no negative consequences. I am not aware if this method destroys the metafield entirely, but would test the following case before using on shared metafields:

Assume product A has metafield X
Assume product B has metafield X
destroy metafield X from product A
does product B still have metafield X?

Perhaps you can adapt this solution to something that works for your needs.

EDIT: Shopify's python online documentation is horrid. I used dir() and help() to find all of this.