How to parse and update group of objects of array


i have message in javascript format which i get from TheHive. I would like then to get object payload.object.tags and put that tag in prepared curl. I have this working when there is only one tag in message. The issue is with multiple tags within one message, cause for the curl, each tag has to be separated by comma, and also have parenthesis: "xxx","xxx","xxx".

Can someone please help me with extracting/updating tags so i can use it in curl accordingly?

Curl example working when there is only one tag:

curl -X POST -uuser:password -k -H 'Content-type: application/json' -H 'kbn-xsrf: true' https://xxxxxx -d '
  "signal_ids": [
    "{{payload.object.tags}}"         //putting tags here, example for case with one tag in javascript msg
  "status": "close"

Example tag format i get in curl -> desired form:

aaaaa,bbbbb,ccccc -> "aaaaa","bbbbb","ccccc"

Now that i look at it, it might be just enough to replace: , by: ","
but it is possible there will be different stuff to get/parse out from tags in future, so dont know if that is the best solution.
Also, as probably visible, i have 0 experience with javascript and just started learning it for this purpose only. Thanks for any advice.

You could join the tags with Javascript or JSONata prior to the template node. At which point you may as well just format the whole string in the function or change node.

[{"id":"6f4eadec.20acd4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload.object.tags","v":"[\"11111111\",\"22222222\",\"3333333\"]","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":1100,"wires":[["3061f894.bc2cd8"]]},{"id":"3061f894.bc2cd8","type":"function","z":"bf9e1e33.030598","name":"","func":"const tags = msg.payload.object.tags.join('\",\"')\nmsg.payload = `curl -X POST -uuser:password -k -H 'Content-type: application/json' -H 'kbn-xsrf: true' https://xxxxxx -d '\n{\n  \"signal_ids\": [\n    \"${tags}\"\n  ],\n  \"status\": \"close\"\n}'`\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":1100,"wires":[["aa67d058.dc70f8"]]},{"id":"aa67d058.dc70f8","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":1120,"wires":[]}]
const tags = msg.payload.object.tags.join('","');
msg.payload = `curl -X POST -uuser:password -k -H 'Content-type: application/json' -H 'kbn-xsrf: true' https://xxxxxx -d '
  "signal_ids": [
  "status": "close"
return msg;

Thank you. That seems to do the trick for what i currently need.
Much love.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.