Unable to update Product metafields via Python API in our custom Python App

WE have a custom ERP application, and basis some event in that we need to add or update the metafield associated to a specific product. We have tried three different code snippets, but the metafileds don’t seem to get added, nor are we getting any error. The code sample is below, and we are testing it by using fixed values .. which will then be replaced by variable values

Code 1

We have tried the foll three code snippets but unable to do so .. can someone guide us how to do this

metafield = Metafield({‘value_type’: ‘value’, ‘namespace’: ‘inventory’, ‘value’: 25, ‘key’: ‘warehouse’, ‘resource’: ‘products’, ‘resource_id’: 7519320604927})
print(“metafields value :”,metafield)
metafield.save()

Code 2
product1 = Product.find(7519320604927)

shopify_request =Metafield({
‘key’: ‘KEY’,
‘value’: ‘VALUE’,
‘value_type’: ‘string’,
‘namespace’: ‘NAMESPACE’,
})
product1.add_metafield(shopify_request)
product1.save()

Code 3
product = Product.find(632910392)
metafield = Metafield({‘value_type’: ‘integer’, ‘namespace’: ‘inventory’, ‘value’: 25, ‘key’: ‘warehouse’})
product.add_metafield(metafield)

Hi @SuneelG ,

If you’re using a newer version of the API (2021-07 and up), you may want to replace the deprecated “value_type” parameter with “type” to make sure that your request is valid.

Dear [email removed] Thanks for pointing me in the right direction. The suggested change got the code working. It’s a pity that there’s no single authoritative documentation for the Python APIs .. and spending unnecessary effort in the wrong direction was getting to be frustrating. If you are aware of any good source to refer for future problems we may run into, we would really appreciate that

Rgds

Hi @SuneelG ,

You’re welcome! As for the docs, you can find the list of the resources for developers here.