Create Order Metafields programmatically but display in UI

Create Order Metafields programmatically but display in UI

A-A-RON1
Shopify Partner
2 0 0

Hi,

I'm looking to create order metafields with the admin rest api. However, I also want that value visible in the UI, since some metafields created via the API are not shown in the UI. I was planning on creating the metafield definition in the UI and then use the admin rest api to create an order with the value for the metafield. However, that doesn't look possible because at the point that the order is created, the metafield is null and therefore not retrievable. If I write the appropriate metafield value in the ui after the order is created, the admin API can grab the metafield. But, that defeats the purpose of doing it programmatically. This is the closest article on the topic: https://community.shopify.com/c/shopify-apis-and-sdks/not-able-to-retrieve-list-of-metafields/td-p/1...

 

Is this possible and if not, what do you suggest? My fallback plan is to make use of line item properties, which would show the values in the UI. But, they are not changeable in the UI, which I'd like to have changeable in the UI if possible.

 

Thanks.

Replies 2 (2)

RalfatGadget
Shopify Partner
11 1 2

Where do you have, or from where do you get the value you'd like to store in the metafield of the order? Is it derived from something that has to do with the products, customer, etc, or is it a fixed value?

 

Ralf

Former Payments product manager @ Shopify, now at making Shopify app development easier for everyone @ Gadget.dev

Jason
Shopify Partner
11206 226 2313

Metafields created via the API can show in the Admin. A while back you would have been correct but things have changed. GraphQL might be new to you but for things like this it's worth learning.

Start looking at GraphQL and creating metafield definitions so they'll be placed into the Admin UI.
There's a workshop that can give you the basics if this is new to you. It's well written and easy to follow. 
 

However, that doesn't look possible because at the point that the order is created, the metafield is null and therefore not retrievable. 

 

This part of the flow I'd want to understand more. There should not be a blocker to update a metafield after order creation so might be missing something here.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★