Add inventory batch details to product variant metafields in Shopify

To enable inventory batch detail metafields on all batch tracked product variants:

1. Navigate to the Preferences tab

2. Scroll down to the Inventory batch metafields section

3. Check the  Enable inventory batch data in metafields for all batch-tracked product variants option

4. Click on  Save to save your preferences

As soon as the preferences are updated, all batch-tracked product variants should have the batch details added to their metafields as a JSON_STRING under the freshly namespace and inventory_batches key. The list of JSON objects will include the most recent 100 batches for each product variant are updated as quantities and properties are changed. These are sorted by the most recently created batches.

Fields available in variant metafields

The following fields are available in each JSON object for each batch:

  • id: Unique identifier for the product variant inventory batch
  • batch_name: Batch name provided in Freshly
  • batch_number: Batch number provided in Freshly
  • barcode: Barcode provided in Freshly
  • invoice_number: Invoice number provided in Freshly
  • description: Description provided in Freshly
  • expiry_date: Expiry date provided in Freshly (format: YYYY-MM-DD)
  • expired_at: When the batch expired at and quantities were removed from Shopify, if removed before the expiry date (format: YYYY-MM-DD)
  • received_date: When the batch was received (format: YYYY-MM-DD)
  • created_at: When the batch was created (format: ISO 8601; E.g. 2020-12-29T23:18:17Z)
  • discounted: Whether the batch is discounted or not (boolean)
  • quantity: Quantity of items remaining in the batch
  • location_id: Shopify location ID for the batch
  • variant_id: Shopify product variant ID the batch belongs to

How to retrieve the product variant metafields

The product variant metafields can be retrieved using either the REST or GraphQL API from the Product Variant resource:

You can also view these metafields right in the admin by appending `/metafields.json` to the end of your variant URL in the admin. 


This URL should display all the metafields. You can filter for freshly namespace and inventory_batches key to retrieve the inventory batch details. 

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us