Hello! I'd appreciate some help with a GraphQL query I have on a custom Shopify flow.
The query is cobbled together from various sources that I found, as I'm not very confident/knowledgeable in writing such things from scratch.
Currently this part returns items that were modified at any point since 00.01 on todays date;
updated_at:>='{{{dateFormat "YYYY-MM-DD[T00:00:01Z]" timeStamp}}}
How could I modify this so that it only return items modified within the last hour? I know this is probably a simple thing to do, but I'm struggling to get started.
Thanks in advance!
Are you writing this write in a graphql query field or as part of a script where you can set variables? The easiest way to do it, if it's running in a script somewhere, is the convert the present time to miliseconds, subtract the miliseconds of your time period (hour, day, whatever), then take that result and covert it back to UTC. Then you have the variable you need and insert it into the query.
Where in your flow are your running this? Could you post screenshots? Might be able to give more direct solutions then.
Also this might be helpful depending on where you are writing the query, but you can create time stamps in handlebars
https://docs.celigo.com/hc/en-us/articles/360039326071-Handlebars-helper-reference#custom-helpers-1:~:text=110-,timestamp,-Returns%20a%20timestamp
1 Like
Hi Craig, thanks for your reply. The query is written in the HTTP request body part of the export step in my flow.
I think a handlebar expression might be the best thing for me to try, as I could effectively experiment outside of the flow until I get the desired result. I'm wondering if I can just use {{timestamp}} - milliseconds equivalent of an hour
or
{{timestamp - milliseconds equivalent of an hour}}
I'll have a play around anyway.
Thanks!
1 Like
I think I'm getting somewhere with this now;
{{dateAdd timestamp -3600000}}
Seems to give me the correct result, so I just need to figure out how to insert that into the query correctly.
1 Like
In case it is useful for anybody else in the future, the exact syntax needed for the handlebar expression in the query (or at least the one that worked for me) was;
{{dateAdd (dateFormat "YYYY-MM-DDTHH:mm:ssZ" timestamp) -3600000}}