Use Flow to update a variant metafield when an order is created

Solved

Use Flow to update a variant metafield when an order is created

Richard687
Shopify Partner
19 1 16

I'm trying (and failing) to create a Flow which is triggered when an order is created and updates a metafield on the variant for each line item. The aim is to have a metafield containing the date when the variant was last ordered.

 

After a few false starts, I created a Flow as follows:

Richard687_0-1708955301499.png

(The "log output" actions can be ignored - they are for debugging.)

 

The "run code" action is fairly simple - it just takes the variant ID for each line item and returns an array of variant IDs:

Richard687_1-1708955412332.png

 

However, the flow is getting stuck on the next action, when it tries to get product variant data. It is configured like this:

Richard687_2-1708955482273.png

But the Flow log is showing this:

Richard687_3-1708956056218.png

The "log output" action has the same code as the "get product variant data" query, and it produces output like this (but with real variant IDs):

 

id:gid\://shopify/ProductVariant/999999999 OR id:gid\://shopify/ProductVariant/999999999 OR id:gid\://shopify/ProductVariant/999999999 

That looks to me like a valid search query.

 

Where am I going wrong? Is my search query incorrect? Perhaps the colons should be escaped differently? Have I missed something somewhere else?

 

Perhaps I am over-complicating this (seemingly straightforward) task, and is there an easier/better way of doing it. Is there an easy way to pull the last purchase date of a variant via the Admin API instead of using Flow?

 

Any thoughts/suggestions would be very welcome.

Accepted Solution (1)

Kalen_Jordan
Shopify Partner
727 34 127

This is an accepted solution.

I think you want just the ID number not the full gid:

 

Screenshot 2024-02-26 at 4.36.46 PM.png

 

Might be helpful to test out queries in graphiql to troubleshoot.

View solution in original post

Replies 5 (5)

Kalen_Jordan
Shopify Partner
727 34 127

This is an accepted solution.

I think you want just the ID number not the full gid:

 

Screenshot 2024-02-26 at 4.36.46 PM.png

 

Might be helpful to test out queries in graphiql to troubleshoot.

Richard687
Shopify Partner
19 1 16

Of course, so simple! A small change to the Run Code action did the job:

Richard687_0-1709031457479.png

 

Many thanks for your help 😊

Kalen_Jordan
Shopify Partner
727 34 127

Nice! You got it!

Anthony__P
Tourist
6 0 0

How did you end up updating the variant metafields? Did you do it with an http request to an app or using the update variant metafield flow action?

Richard687
Shopify Partner
19 1 16

I used the "Update product variant metafield" action. Here's the final flow: 

Richard687_0-1712304923996.png