Hi everyone,
I am new to working with the Shopify API and currently developing a simple app for a client. Part of this app involves updating a custom metafield in the customer profile. However, when I retrieve customer data and print a list of all metafields, the custom metafield (namespace: custom, key: kundennummer) is not listed, even though the customer has filled out these fields.
Here is the relevant part of my code:
try:
# FIND CUSTOMER NUMBER
client_number = None # Initialize client_number
metafields = shopify.Metafield.find(owner_id=customer_id, owner_resource="customer")
if metafields:
for mf in metafields:
if mf.namespace == "custom" and mf.key == "kundennummer":
client_number = mf.value
print(f"Customer number found: {client_number}")
break
else:
print(f"Customer {customer.id} has no metafields.")
client_number = "unknown"
except Exception as e:
# Error handling
print(f"Error retrieving metafields: {e}")
I am using API version 2024-04, and in the metafield creation, I have enabled both write and read access for API access.
What am I missing or doing wrong?
Please note: when I print a list of all metafields, it shows various metafields from, for example, a cookie banner app, but not the custom metafields I have set up.
Any insights or suggestions would be greatly appreciated!