How can we help?

Lichen Zhang
Written by Lichen Zhang

Add batch details in metafields to Shopify orders

Enable batch details in Shopify orders using JSON string metafields. This is currently available on all plans except Freshly Essential.


If you would like to retrieve batch metafield data from your Shopify orders, now you can easily enable these in your preferences section.

Click on the Preferences tab in Freshly and navigate to the Order fulfillment section.

Click on Enable batches metafields on customer orders in the Order fulfillment section.

Once this option is enabled, all future order updates will automatically update the metafields on the orders.

To view the order metafields directly in Shopify:

  1. Navigate to your orders page. E.g. https://freshly.myshopify.com/admin/orders/3655881064506
  2. Add the `/metafields.json` to your order URL.
  3. This should display the JSON string metafield under the namespace freshly and key inventory_batches.

The JSON string metafield can be used in liquid templates directly in Shopify without parsing the string. However, if you are using a custom script to push to 3PL or ERP software, you will need to parse the string so it is readable by your script or application. Below is an example of how to do this in Ruby.

> order = ShopifyAPI::Order.find(3655881064506)
> order.metafields.first.value
=> "[{\"id\":6016,\"expiry_date\":\"2021-03-21\",\"received_date\":\"2021-03-19\",\"created_at\":\"2021-03-19T00:49:18Z\",\"location_id\":2,\"location_name\":\"My Location\",\"batch_name\":\"Batch 2021-03-18 20:49:18\",\"barcode\":null,\"invoice_number\":null,\"description\":null,\"line_item_id\":9382097525,\"quantity\":2}]"
> JSON.parse(order.metafields.first.value)
=> [{"id"=>6016,
  "expiry_date"=>"2021-03-21",
  "received_date"=>"2021-03-19",
  "created_at"=>"2021-03-19T00:49:18Z",
  "location_id"=>2,
  "location_name"=>"My Location",
  "batch_name"=>"Batch 2021-03-18 20:49:18",
  "barcode"=>nil,
  "invoice_number"=>nil,
  "description"=>nil,
  "line_item_id"=>9382097525,
  "quantity"=>2}]

Feel free to reach out to us if you have any questions about metafields or how to integrate Freshly with your third-party apps and software.

Categories: