Shopify Storefront API - Adding metafield to order not working

78 Views Asked by At

I'm currently trying to use the cartMetafieldsSet query in the Storefront API to add user generated information on to the order.

The below query seems to successfully add the metafield onto the cart object, however after proceeding to the checkout and paying, the metafield on the order is blank.

I have a couple of questions

  1. Does anyone know why the metafield isn't showing on my order?
  2. Is there a difference between cartMetafieldsSet on the Storefront API and the metafieldsSet on the admin API?
// GraphQL Query
mutation cartMetafieldsSet($metafields: [CartMetafieldsSetInput!]!) {
  cartMetafieldsSet(metafields: $metafields) {
    metafields {
      # Metafield fields
      createdAt
      description
      value
    }
  }
}

// Variables
{
  "metafields": [
    {
      "key": "custom.test",
      "ownerId": "CART_ID",
      "type": "multi_line_text_field",
      "value": "This is a test value"
    }
  ]
}

Here is how I defined my metafield in Shopify

Shopify metafield

Thanks for your help!

1

There are 1 best solutions below

0
David Lazar On

You're mixing two concepts. A cart is not an order. A cart metafield can be set with Storefront API sure. You do that to affect checkout. In checkout you get a cart, and you look at the metafield, and perhaps that helps in checkout.

But once Shopify has converted a checkout to an order, what makes you think you are going to find a metafield set on the cart? If you want to capture information in a cart, use cart attributes or a note. Those show up in order fine.