Output is always wrong with wrong properties

Output is always wrong with wrong properties

KafLongHair
Shopify Partner
2 0 0

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.

Replies 3 (3)

paul_n
Shopify Staff
1577 170 363

One obvious thing - your input query should not have a comma in it. Also, neither should your Output schema

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
KafLongHair
Shopify Partner
2 0 0

Good catch! I removed the commas and the problem remains.

paul_n
Shopify Staff
1577 170 363

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. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.