Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Input:
query{
order{
createdAt,
cancelledAt
totalPriceSet {
presentmentMoney{
amount
}
}
}
}
Code:
export default function main({order}) {
const
tenDaysInMillis = 10 * 24 * 60 * 60 * 1000,
orderTimestamp = new Date(order.createdAt).getTime(),
cancellationTimestamp = new Date(order.cancelledAt).getTime(),
total = order.totalPriceSet.presentmentMoney.amount;
let response;
if (cancellationTimestamp - orderTimestamp <= tenDaysInMillis) {
response = {
refundAmount: total,
refundMessage: "Full refund - cancelled within 10 days policy"
};
} else {
response = {
refundAmount: total * 0.9,
refundMessage: "90% refund - 10% cancellation fee after 10 days policy"
};
}
console.log("response",response);
return response;
}
Output
type Output {
refundMessage: String!,
refundAmount: Float!
}
And the console.log returns correct:
response
{
"refundAmount": 29.95,
"refundMessage": "Full refund - cancelled within 10 days policy"
}
The Step Input data gives:
{
"order": {
"cancelledAt": "2025-01-30T20:49:12Z",
"createdAt": "2025-01-30T20:19:29Z",
"totalPriceSet": {
"presentmentMoney": {
"amount": 29.95
}
}
}
}
But the Step output gives:
{
"message": [
"[\"response\",{\"refundAmount\":29.95,\"refundMessage\":\"Full refund - cancelled within 10 days policy\"}]"
],
"return_value": {}
}
I even tried with the default but also returns nothing.
What am i doing wrong? Thanks for the help.
One obvious thing - your input query should not have a comma in it. Also, neither should your Output schema
Good catch! I removed the commas and the problem remains.
I suspect it's working correctly. What is the problem exactly? I assume you are trying to use the info in a step after Run code, but you haven't provided details about that.
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025