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.
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025