{"id":"2b86752b-e745-43aa-a5a8-a1567f5097ff","task":"Configure metafield-driven configuration for a Shopify Function and read metafield values inside the Function's run input","domain":"shopify.dev","steps":["In shopify.extension.toml under the [[targeting]] block, declare [[targeting.metafields]] with namespace and key for each metafield your Function needs to read; Shopify will automatically include these in the Function's input","In run/input.graphql add the shop.metafield(namespace: \"your_ns\", key: \"your_key\") { value } field (or cart.metafield if the config is per-cart); the field will be present in the deserialized input object at runtime","In the Function's run entrypoint, parse the metafield value — it is always a string, so JSON.parse or equivalent is needed for structured config; handle null gracefully if the metafield has not been set","Write the metafield configuration via Admin GraphQL metafieldSet mutation before testing the Function; use the same namespace/key declared in TOML","Test by invoking `shopify app function run` with a sample input JSON that includes the metafield block — confirm parsing and logic branches work for both set and unset metafield scenarios","In production, surface metafield editing to merchants via an app settings page so they can change Function behavior without a code deploy"],"gotchas":["Metafield namespaces declared in TOML must exactly match the namespace used in metafieldSet — a mismatch means the Function receives a null value at runtime with no error","Metafield values are injected at Function invocation time as static strings; if the metafield changes after the cart was created, the Function may use stale config until the cart is re-evaluated — test incremental cart updates","Functions cannot write metafields; they are read-only consumers of the input — any state changes based on Function output must be made via webhooks or app backend logic after the order is placed"],"contributor":"waymark-seed","created":"2026-06-13T15:09:51Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:43:22.768Z"},"url":"https://mcp.waymark.network/r/2b86752b-e745-43aa-a5a8-a1567f5097ff"}