I am trying to update product meta fields using a python script via the Shopify API. I have tried so many things and made sure that the meta fields exist, used the correct name space and keys in the code. But they are somehow invisible to the code. The code retrieves other meta fields, but not the ones I want to update. The difference between the two groups of meta fields is that, the ones the code retrieves are created programmatically and are of the type multi line text and the others are also created by a python program but are of the type rich text field. Here is the code snippet that tries to extract meta fields:
def get_metafields(product_id, namespace, key ![]()
âââFetch metafields and filter by namespace and key.âââ
url = f"{SHOPIFY_BASE_URL}/products/{product_id}/metafields.json"
try:
response = retry_request(requests.get, url, headers=headers)
response.raise_for_status()
all_metafields = response.json().get(âmetafieldsâ, )
logging.debug(f"All metafields for product {product_id}: {all_metafields}") # Log all metafields
filtered = [
m for m in all_metafields
if m[ânamespaceâ] == namespace and m[âkeyâ] == key
]
logging.info(f"Found {len(filtered)} metafields for key â{key}â and namespace â{namespace}ââ)
return filtered
except requests.exceptions.RequestException as e:
logging.error(f"Error fetching metafields: {e}â)
if hasattr(e, âresponseâ ![]()
logging.error(f"Response content: {e.response.text}")
return
- The meta fields are pinned and are visible on the product admin.
- Storefront API access
Definitions can be used in your custom storefronts and related apps is toggled on.
Had anyone like this problem before? Can someone help me or show a way to solve this problem?
Thanks in advance
Mikias