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-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!

1 Like

Hi Adam,

I have a question regarding to your post.
Now I am trying to make an app which enables to update varient metafields, and I’m struggling to it.

My question is… is it possible to use this request body to update varient metafields?
{
“metafield”: {
“id”: {api.id},
“value”: “newvalue”,
“value_type”: “string”
}
}

I assume that there is something that I have to modify this body, but I tottally have no idea.

I’m new to Parabola ,developing API, and writing a request body…so easy on me :expressionless:

Moreover, if you know an article which indicates how to make a request body, please let me know!!

Hi @Hideki_Amiya :wave:

Good question! Using that request body is the correct way to update the value of a variant metafield in Shopify. Have you successfully pulled in a list of your current variant metafields using the snippet above?

If so, you will notice the Pull from ShopifyGet Product Variant Metafields steps return a list of metafield IDs that we’ll use to target and update a metafield.

The column containing those IDs is called api.id. That column is necessary so Parabola can dynamically target which metafields to update in Shopify. My current metafield values in the {api.value} column are currently set to Test Value:

To update the values of your metafields, you just need replace newvalue with the literal value you want to use. Here’s an example of how I can change my metafield values to Parabola Metafield TEST:

You can also dynamically reference another column’s values and insert them as metafields by referencing the column name in curly brackets.

{
	"metafield": {
		"id": {api.id},
		"value": "{My Column With Values}",
		"value_type": "string"
	}
}

Let me know if that helps!
Daniel

1 Like

Hi @daniel

Thanks to you, I almost accomplish to make this flow! :+1:

I kind of understood authentication, requestheaders, and managed to set Get Product Variant Metafields.
Also I got the point why you mentioned Pull From Shopify!

Then I tried to replace the values in api.value with column leadtime, however it does not seem to work.

Here is what I would like to do:
Column leadtime is latest information so that I would like to update the values in api.value.

And here is what I wrote:

Please give me some mercy and help!
Hideki
https://parabola.io/app/flow/vjJrXxZa2D

Hi @Hideki_Amiya

You’re very close! Have you tried publishing and running your flow? You should be able to do this by clicking the Run Flow button in the top-right corner of the page.

If you refresh your Parabola flow or check your Shopify store, the variant metafields should be updated with the values from your leadtime column.

Hi @daniel

I’ve run my flow, but it failed partially.
Here is where I’m in trouble:

Could you give some further advice to fix this?
Aside from Update a metafield, Everything seems to be alright.

Just in case, I copied the error message.

### Partially Failed

Today at 5:25pm +09

35s elapsed

9,997 max rows processed

0 run credit

Enabled Exports:

Create new Metafield for a Product resource

(0 rows)

Add a Metafield to an Existing Variant

(0 rows)

Update a metafield

(0 rows)
{
  "auth": {
    "password": "(I deleted)",
    "username": "(I deleted)"
  },
  "data": {
    "metafield": {
      "id": 19521492549737,
      "value": "10営業日以内に発送",
      "value_type": "string"
    }
  },
  "headers": {
    "Content-Type": "application/json",
    "X-Shopify-Access-Token": "(I deleted)"
  },
  "httpAgent": {
    "_events": {},
    "_eventsCount": 0,
    "freeSockets": {},
    "lookup": false,
    "maxFreeSockets": 1,
    "maxSockets": 1,
    "maxTotalSockets": null,
    "options": {},
    "proxy": {
      "host": "socks-proxy-fcaa5440d0eacbaa.elb.us-west-2.amazonaws.com",
      "port": 1080,
      "type": 5
    },
    "requests": {},
    "sockets": {},
    "timeout": null,
    "tlsConnectionOptions": {}
  },
  "httpsAgent": {
    "_events": {},
    "_eventsCount": 0,
    "freeSockets": {},
    "lookup": false,
    "maxFreeSockets": 1,
    "maxSockets": 1,
    "maxTotalSockets": null,
    "options": {},
    "proxy": {
      "host": "socks-proxy-fcaa5440d0eacbaa.elb.us-west-2.amazonaws.com",
      "port": 1080,
      "type": 5
    },
    "requests": {},
    "sockets": {},
    "timeout": null,
    "tlsConnectionOptions": {}
  },
  "method": "PUT",
  "url": "(I deleted)"
}

Hi @Hideki_Amiya,

The 404 error means that the metafield id that you are trying to update does not exist or is incorrectly being passed in your API Endpoint URL.

Most likely, your endpoint is referencing the {metafield_id} which is pasted directly from Shopify’s documentation. Since that column doesn’t exist, reference the {api.id} column in Parabola to pass the correct metafield ids into your endpoint.

PUT /admin/api/2022-01/metafields/{api.id}.json

Hope that helps!

Hi @daniel

Amazing! Mostly I made it! :pray:

You were right! I referred the {api.id} column in Parabola to pass the correct metafield ids into my endpoint, and that works properly.

Moreover, I made a bit change about request body which are parts of valuetype and string.
Since Adam_r cited value_type and string, but it actually “valuetype” and “string!”. I assumed that "_"is not necessary for valuetype, and “!” is needed for string.

By the way, I still have two question about my flow.

First
Are there better ways to avoid 429 errors instead of using limit rows?

I ran this flow, and then, Get Product Variant Metafields causes a problem which is too many requests(error 429). What I’m doing now is to limit the number of rows by 100.

Second
Are there any ways to stop this flow when there are no rows to update?

I found that after it conducts Filter rows and there are now rows left on the table, this flow occurs error in the part of Filter rows(1). Then The error email reached me out.
However, if there are no rows left, it means it does not have to update the metafiled.
I tried to use if/else column and other features, but I’m struggling on it.

Sorry for long-long sentence, I’m looking forward to your reply!

Hi @Hideki_Amiya

Glad to hear a simple fix to the API Endpoint URL solved that issue! Thanks for calling out the updates to Shopify’s documentation around the value_type and string! values.

Rate limiting can be a balancing act. According to Shopify, their limit allows up to 2 requests per second for Standard plans and 4 requests per second for Shopify Plus plans.

In most cases, the best way to ensure you’re not being rate-limited is to set the Maximum requests per minute value in Parabola.

image

For your Filter rows (1) error, try using an Insert text column step first to create those columns. Just be sure to toggle Skip if column already exists. Check out this thread for more information on how to set that up.

From there, you’ll be able to target those columns and completely filter them out ensuring that no updates will be pushed to your metafield export.

Hi @daniel

Nearly I accomplished.
I still could not understand why Skip if column already exists fixes this proble, but this is amazing.

One thing that I cannot fix is:
If the number of rows are over 200, it ends with error 406 even though I set 60 requests per minute on the rate limiting.

As long as I read the error of the request, the part of id is null. This might be the problem, however I do not serach what I have to do.

{
  "auth": {
    "password": "****(I deleted)",
    "username": "****(I deleted)"
  },
  "data": {
    "metafield": {
      "id": null,
      "value": "1~2営業日以内に発送",
      "valuetype": "string!"
    }
  },
  "headers": {
    "Content-Type": "application/json",
    "X-Shopify-Access-Token": "****(I deleted)"
  },
  "method": "PUT",
  "url": "https://****(I deleted)@****(I deleted).myshopify.com/admin/api/2022-01/metafields/.json"
}

Hi @Hideki_Amiya,

It looks like you set up the “Insert text column” step to generate the api.id column correctly. This should resolve The column api.key no longer exists error.

In order to make a successful PUT request, a valid metafield id must be passed. If you look at your API Endpoint URL, you can see the url is missing an id:

...2022-01/metafields/.json

My guess is that you have a product variant that does not have a metafield associated with it. When enriching your data, it does not return an api.id value which causes the final API request to error out.

Check to see if any of your rows have a blank cell value for api.id after 200 rows, as that may be causing the error. To solve this, use a “Filter rows step” to remove rows where api.id is blank. That will ensure valid requests are being made!

1 Like

Hi @daniel

Mission accomplished!
It works properly, and I really appreciate everything you told me.

Your guess was right, we have a product variant that does not have a metafield associated with. And it was a test page.

Have a lovely weekend,
Hide

2 Likes