Closed kiyology closed 8 years ago
Sounds like an awful confusion regarding JSON representation. Do you parse the input as JSON string inside the yamas2-action.js file? Would you be able to show the code for that? I'll try to repro the situation locally and suggest an approach. Hang tight.
Thanks for the reply!
Yes, I'm parsing the input as JSON string inside yamas2-action.js file.
The way I'm parsing it is payload = JSON.parse(process.argv[2]),
I printed it out the whole command through st2 execution get, the json string was being passed as an argument like {u''recovery_alerts'':
. With single quotes and the charater 'u', the script was unable to parse it.
I reproed the issue on my box. It looks like things are working per design but don't work well for your use case. Let me explain.
trigger.body is sent as an object correctly to the workflow. So type of payload in the workflow is indeed an object. The problem is in the following line:
action: core.local cmd="node /opt/stackstorm/packs/examples/actions/yamas2-action/yamas2-action.js <% $.payload %>"
This is equivalent of you trying to pass an object in the command line which has no meaning. Unfortunately YAQL doesn't seem to support a toJSON method which we could have used to pass the actual string rep to the script which would then work. So your options at this point are to actually pass flattened parameters to the script instead of the object.
For example,
action: core.local cmd="node /opt/stackstorm/packs/examples/actions/yamas2-action/yamas2-action.js <% $.payload.get('param1') %> <% $.payload.get('param2') %>"
I hope the example I gave you makes sense. We'll see how to clear up the confusion in docs or something. You can also ping me on slack for more interactive help.
Thanks for the detailed explanation! So if I want to use the whole json to the script (because I need many fields and passing them one by one through <% $.payload.get('param1') %>
might not be efficient), I assume there's no proper way of doing this, right?
@kiyology I am not sure about proper but you could add another step in the mistral workflow that translates an object to a JSON string and then passes the string to next step in the workflow as input. LMK if this isn't clear and I can whip up an example. We talked a bit about supporting JSON transformations as first class YAQL function. We might add this in future releases but no promises there.
@kiyology Can I close this issue?
Yes, thank you so much for your help! :)
Hi,
I'm experiencing this issue when using stackstorm: Here's my action config:
Here's my workflow config:
Here's my rule config:
Basically I'm having a webhook and sends the payload received by the webhook to a mistral workflow action, which takes the payload as the third parameter. Everything works fine except that when it's executing, the double quotes inside payload JSON has been substituted by two single quotes which is causing my script to fail when parsing it as a JSON.
Here's the execution detail:
And there's a character 'u' in front of all the beginning two single quotes of a string. I tried using payload as a string or object. If I use payload as a string, I don't get the character 'u', but all the double quotes are still replaced by two single quotes.
And idea why?
Thanks!