When I test my Flow Action, I’m not seeing the JSON object I return.
This action didn't return an output when it ran. Most often, this is because the action doesn’t return data or the returned data wasn’t used. In rare cases, it may also be that the output exceeded system limits.
I’ve looked at other forum posts, but they use the deprecated json() function. I think this is no longer necesssary in Remix (v2.17.0), though I did try that too. The Run Code examples seem to just return a simple JSON object:
[[extensions]]
name = "My Flow Action (dev)"
handle = "my-flow-action"
type = "flow_action"
uid = "<redacted>"
description = "Do a thing"
runtime_url = "https://example.com/api/my-flow-action"
schema = "./schema.graphql"
return_type_ref = "ReturnType"
schema.graphql:
type ReturnType {
message: String!
}
Here’s a stripped down version of my code:
export async function action(args: ActionFunctionArgs) {
const {request, params} = args;
return { message: "This is a returned message." };
}
I tried including a “Log output” object downstream of my action. I gave it a sample text message “Output message”, which is displayed but nothing else. When I tell it to show the input field {{ message }} it throws an error saying that’s not available:
Thanks @JordanFinners. I tried the code (no change, no output), but I’m afraid you’ll need to be more specific on “logged out or used in your flow”. How do I do either of those things? As I explained above, I tried using a Log output object, but I can’t refer to any of my output fields and I tried using console.log(), but that function (logically) only writes to my server’s log, not the output object.
Right, thank you @JordanFinners. That was the missing piece. The Log Output object needs to log {{ message }}, but it has to do it within an extension-specific scope. Turns out that scope isn’t defined anywhere in schema.graphql or shopify.extension.toml: it’s a camel-case conversion of name (not handle).
So for “My flow action” (my-flow-action), the scope was myFlowAction, so I had to log (body of Log Output) {{ myFlowAction.message }}, then it worked.