Working with Shopify Metafields in Parabola (Product & Product Variant)

Hi everyone :wave:

Wanted to share what we have learned about working with Shopify metafields in Parabola! While we do not yet offer the ability to create/ modify metafields with the native integration, we can use our API steps to work with metafields.

For starters, information on metafields is spread through a few different pages in Shopify’s documentation:

Depending on how you structure your products, metafields can be created at the product or product variant level:

  • To create product metafields: /admin/api/2021-04/products/{Product: Id}/metafields.json

Request Body
{
“metafield”: {
“namespace”: “inventory”,
“key”: “warehouse”,
“value”: 25,
“value_type”: “integer”
}
}

  • To create product variant metafields: /admin/api/2021-04/variants/{Variants: Id}.json

{
“variant”: {
“id”: “{Variants: Id}”,
“metafields”: [
{
“key”: “new”,
“value”: “newvalue”,
“value_type”: “string”,
“namespace”: “global”
}
]
}
}

After creating a metafield, you can find the ‘Metafield ID’ (which is required for updating a metafield) by using an “Enrich with API step” (the metafield ID will be returned as api.id). To find the metafield ID, we must first provide a Product/ Variant ID. We will retrieve these values by pulling in Products (with Variants if applicable) with a “Pull from Shopify” step before connecting to our “Enrich with API” step, where we will retrieve metafield IDs.

Once we have Product/ Variant IDs, we can find the metafield ID through a GET request:

  • To get product metafields: /admin/api/2021-04/products/{Product: Id}/metafields.json

  • To get product variant metafields: /admin/products/{Product: Id}/variants/{Variants: Id}/metafields.json

Now that you have your metafield ID, we can dynamically pass this value to our “Update a Metafield” API step:

  • Update a metafield: /admin/api/2021-04/metafields/{api.id}.json

{
“metafield”: {
“id”: {api.id},
“value”: “newvalue”,
“value_type”: “string”
}
}

NOTE: The endpoint for updating metafields can only be used for modifying the metafield’s value. If you’d like to update the metafield’s namespace or key, you must delete the current metafield and create a new one.

If you plan on working with Shopify metafields in Parabola, we recommend using this snippet as a starting point (how to use a snippet in Parabola). We preconfigured all of the aforementioned API steps to hopefully make your life easier! Just paste this string right into your canvas to start building: parabola:cb:fad25986600549c5b00860999eae69ae

Hope this helps! Feel free to comment any questions below, and we will continue to update this post as we continue to learn more about working with metafields in Shopify!