Hi everyone
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:
- Add a metafield to an existing product
- Add a metafield to an existing variant
- Retrieve/ Create/ Update a new metafield for a Product resource
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-10/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-10/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-10/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-10/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:870ed1a13332488eb883f97661ca0b97
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!