Shopify app - Cart transform - metafields

Topic summary

A developer is struggling to properly set and retrieve metafields for a Shopify cart transform extension.

Initial Problem:

  • Using $app:test_namespace in the CreateAppDataMetafield mutation causes an “Unexpected system error”
  • Removing $app allows creation but returns null when querying in cart-transform
  • The metafield is visible in Liquid theme files but not accessible in the cart transform query

Solution Provided:
Two key issues were identified:

  1. When setting app metafields, the $app: prefix is redundant since the owner is already the app installation
  2. The metafield is being created with the app installation as ownerId instead of the cart transform object itself

Recommended Approach:

  • First create a cart transform using cartTransformCreate mutation
  • Obtain the cart transform ID (format: gid://shopify/CartTransform/<id>)
  • Use metafieldSet mutation with the cart transform ID as ownerId

Outstanding Question:
A follow-up request asks for code examples on retrieving the cartTransform ID and calling it from the extension (currently unanswered).

Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

I set the fields in “shopify.extension.toml

[extensions.input.variables]
namespace = "$app:test_namespace"
key = "test_key"

I use CreateAppDataMetafield mutation to create/set the metafield. When I use the namespace: “$app:test_namespace”, I get an error: “Unexpected system error. Try again later.

If I remove $app and use namespace: “test_namespace” I don’t see the error.

But then I want to get this value in my input.query in cart-transform

I am trying to get this value in two ways

1 way

query Input {
  cartTransform {
    test: metafield(namespace: "$app:test_namespace", key: "test_key") {
      value
    }
  }
}

2 way

query Input {
  cartTransform {
    test: metafield(namespace: "test_namespace", key: "test_key") {
      value
    }
  }
}

None of them works and returns null value

I can see the value from this metafile on the liquid file through the theme-extension

Do you know how I can retrieve and set this metafield?

1 Like

There are two issues here:

  1. You are trying to set a metafield where the ownerId is your app installation. Nothing wrong with that, but the error you are getting **Unexpected system error. Try again later.**, which has a very useless error message, is due to the fact that when setting app metafields, the $app part of the namespace is not needed, because it’s already an app owned metafield since its owner is your app, so adding $app: would be redundant.
  2. You are creating a metafield that has ownerId your app installation instead of the cart transform object.

You should create a cart transform using the cartTransformCreate mutation, then once you have the cart transform id (which should look something like this gid://shopify/CartTransform/<id>) you can go ahead and run the metafieldSet mutation with the ownerId variable as the cart transform id instead of your app installation id.

Hope this helps!

Hi there, I don’t find the way to get the cartTransform Id after it has been created, could you share some code examples on how to get it? and how to call it from the cart-transform extension?