Shopify Python API Delete a customer metafield
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 (https://github.com/Shopify/shopify_python_api)
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": metafield.destroy()
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.
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.