Metafields attached to draft order are not carried over to created order

Metafields attached to draft order are not carried over to created order

Leo_Bossmann
Shopify Partner
12 0 9

Hi there,

I am generating a draft order with the admin api, using this query:

mutation ($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      invoiceUrl
    }
    userErrors {
      field
      message
    }
  }
}

Variables:

{
  "input":{
    "useCustomerDefaultAddress":true,
    "tags":"Return",
    "metafields":[
      {
        "namespace":"noni_returns",
        "key":"order_reference",
        "description":"Original order",
        "value":"gid://shopify/Order/237645273645276",
        "valueType":"STRING"
      }
    ],
    "customerId":"gid://shopify/Customer/87346583765",
    "note":"Test comment",
    "lineItems":[
      {
        "variantId":"gid://shopify/ProductVariant/284756293847",
        "quantity":1
      },
      {
        "variantId":"gid://shopify/ProductVariant/38475638475687",
        "quantity":1
      }
    ]
  }
}


The draft order is created correctly, but when I convert it to an actual order by using the invoiceUrl only the tags and the note are carried over, the metafields are not.

Is there a way to attach meta information to a draft order that will show up in the resulting order?

Thanks in advance,

Leo

Replies 4 (4)

_JCC_
Shopify Staff
200 27 55

Hey @Leo_Bossmann ,

The behaviour of the metafield resource not being on the related order from the completed draft order is expected. As a possible work around, utilizing a draft_orders/update web hook would allow you the opportunity to  migrate the metafields you want to the connected order when the draft order completes.

I think there's definitely value in auto creating the metafield on the resulting order, so I'll be sure to share this with the appropriate team.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Leo_Bossmann
Shopify Partner
12 0 9

Hi John,

I think there's definitely value in auto creating the metafield on the resulting order, so I'll be sure to share this with the appropriate team.

Thanks, I appreciate it!

For now I have worked around the problem by using custom attributes (additional details), but I'll look into the draft_orders/update webhook!

Take care,

Leo

_JCC_
Shopify Staff
200 27 55

Hey Leo, 

I might actually like your approach better :-). The custom attributes get moved over already and you have that working. Maybe the web hook approach and migrating metafields yourself might not prove to be overly beneficial, but I'll leave that with you. If you have any other questions let me know.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

DiscountNinja
Shopify Partner
104 0 67

@_JCC_ @Leo_Bossmann Just wanted to weigh in here and share an issue with using the custom attributes (note attributes) approach:

- Note attributes are not a good candidate to store information that should not be visible to customers; some integrations send the notes to back-end systems that may result in notifications being sent to the customer that include the note attribute

We would like the ability to add a (private) metafield to a draft order and ensure it is moved over to the order automatically.

That would allow us to store the technical information related to the draft order in a proper fashion.

Bart Coppens | Limoni Apps | Building apps for Shopify since 2016