Creating automated inventory alerts via Shopify Flow using product metafields for customer email storage

I want to build an automated system that notifies customers when products come back in stock. My plan is to save customer email addresses in a product metafield as a comma-separated string, then use Flow to read this data and send individual emails when inventory is replenished.

My current workflow looks like this:
Scheduled trigger → Product data retrieval → Code execution → Output logging

I can see the email list when I log the metafield directly, but I’m struggling to access these emails within the code execution step where I need to parse them and send notifications.

I’m having trouble understanding how the code execution section works. I’ve tried querying the metafield in the inputs:

query {
  product {
    metafield(namespace: "custom", key: "stock_notification_emails") {
      value
    }
  }
}

This always returns NULL when I log it. I also tried accessing it directly in the code:

const emailList = input.stock_notification_emails;

This also returns NULL. How do I properly access metafield data within the code execution step?

Another problem is that the marketing message action seems to require customer IDs instead of email addresses. Is there a way to convert email addresses to customer IDs?

Am I approaching this correctly or is there a better method?

I’ve hit this same metafield issue in Flow. Your scheduled trigger doesn’t have product context, so the metafield query returns NULL. You need to loop through products first, then grab their metafields. For the code step, restructure your workflow with a product-based trigger or loop through products using the REST Admin API in your code block. Try shopify.rest.Product.all() to get products, then access metafields for each. For the customer ID conversion, use the GraphQL Admin API to search by email: customers(first: 1, query: "email:${emailAddress}"). This gives you the customer ID if they exist. Honestly, storing emails in metafields as comma-separated strings is pretty fragile. I’d consider a proper back-in-stock app or build a custom solution with webhooks and a separate database table for notifications. Way more reliable and won’t slam your API limits.

Yeah, metafield access in Flow is a pain. Skip the GraphQL and use liquid syntax in your code step instead - try {{ product.metafields.custom.stock_notification_emails }}. Just watch out for comma-separated emails - they’ll break if someone adds invalid formats or extra spaces.