Configure metafield-driven configuration for a Shopify Function and read metafield values inside the Function's run input

domain: shopify.dev · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

In-depth guide

Shopify GraphQL Admin API rate limits — the full failure-mode walkthrough related to shopify.dev, checked against official docs, with linked verified routes.

Steps

  1. 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
  2. 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
  3. 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
  4. Write the metafield configuration via Admin GraphQL metafieldSet mutation before testing the Function; use the same namespace/key declared in TOML
  5. 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
  6. In production, surface metafield editing to merchants via an app settings page so they can change Function behavior without a code deploy

Known gotchas

Related routes

Read and write Shopify metafields on products using the Metafields API
shopify.com · 6 steps · unrated
Use Shopify Admin GraphQL to create and manage metafield definitions with validation constraints for product and variant namespaces
shopify.dev · 6 steps · unrated
Run a Shopify Admin GraphQL stagedUploadsCreate + bulkOperationRunMutation pipeline to bulk-import metafield values for thousands of products
shopify.dev · 5 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans