[How do i...] add this in a post request HTTP node

I’m needing to add an array to a post request

image

Not sure the best way to add these into the value correctly.
[ { “ip”: { “ip”: “8.8.8.8/32” } }]

I feel I should know this, but my mind is blank. (don’t want to change it to a RAW post if I can help it)

Hi @RedPacketSec, the example you have provided would be converted to a String when sending the request. To send a JSON object as the body you’d need the JSON/RAW Parameter option indeed.

I was hoping i didnt have to do that :frowning:

that’s annoying, but thanks for the confirmation

Can you try also setting an expression in the Value field? For example: {{[{ "ip": { "ip": "8.8.8.8/32" } }]}}

1 Like

i’ll give it another go when back at pc

1 Like

ok so what i asked was solved and works great, but now you have unlocked level 2 :wink:

is this possible, getting the SSH stdout where 8.8.8.8 should be and keep it an array, so far I’ve managed to replicate the format but its not an array, I keep breaking it

Do you have that value saved in a variable?

Out of interest when setting your object there did you try using the set node and using ip.ip then when sending just use { { {{$node["Set"].json}} } }

image

That would then in theory give you the same json you are sending.

yes i used the set node, no, i didnt try ip.ip :wink: will give it a try

I only found out about that little trick the other day.

So what you could do is use a function item node and just do $node["Set"].json["ip"]["ip"] = $node["SSH"].json["stdout"];

Then next time you use $node["Set"].json it will have the ip set to your return result. It is not pretty but the example below shows it in action.

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "privateKey",
        "command": "echo \"12.12.12.12\""
      },
      "name": "SSH",
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [
        580,
        300
      ],
      "credentials": {
        "sshPrivateKey": {
          "id": "32",
          "name": "SSH Private Key account"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "ip.ip",
              "value": "8.8.8.8/32"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        410,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "$node[\"Set1\"].json[\"ip\"][\"ip\"] =  $node[\"SSH\"].json[\"stdout\"];\n\nreturn item;"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "test",
              "value": "={{$node[\"Set1\"].json[\"ip\"][\"ip\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set2",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        950,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SSH": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set1": {
      "main": [
        [
          {
            "node": "SSH",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FunctionItem": {
      "main": [
        [
          {
            "node": "Set2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

nice will give it a try when I get a few mins spare to pop back and play with my n8n stuff, cheers

1 Like