HTTP Post JSON Object

Hi Folks,

a question: How can i send a JSON via HTTP Post ?

"patient": {
  "dob": "1970-01-01",
  "firstName": "General"
}

I like to send it without JSON/RAW Parameter.

Any idea ?

Regards,
Stefan

You can do this:

{
  "nodes": [
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://enhvqn6yaa58q.x.pipedream.net",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"patient\": {\n    \"dob\": \"1970-01-01\",\n    \"firstName\": \"General\"\n  }\n}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        400,
        300
      ]
    }
  ],
  "connections": {}
}
1 Like

Thanks, Jan !! I have made it like you sample.

2 Likes

I’ve had issues by the escaping of " and had to use raw instead. Is raw the only way if you have nested json and can I include values from previous steps there as well?

Sometimes it’s possible to use one type of quotation marks (e.g. ") outside and another type (e.g. ’ ) inside. Like '{ “nodes”: [ { “parameters”: { “requestMethod”: “POST”, “url” [...]'
Not sure if this works here, just an idea.

In the expression editor you usually have access to all existing nodes in your workflow so you should be able to select other values there. I let the workflow run one time so it shows more options (at least that’s what I think) to choose from.
HTH

I think so. I’ve never managed to use the selectors for a nested .json either.

Not sure if understand the problem. Here are how you can access deep level data from a previous node and return it as a string. For the lowest level I gave two examples. But the same is possible for all levels:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      a: {\n        b: {\n          c: 'asdf'\n        }\n      }\n    }\n  }\n]"
      },
      "name": "Mock Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "a",
              "value": "={{JSON.stringify($node[\"Mock Data\"].json[\"a\"])}}"
            },
            {
              "name": "b",
              "value": "={{JSON.stringify($node[\"Mock Data\"].json[\"a\"][\"b\"])}}"
            },
            {
              "name": "c1",
              "value": "={{$node[\"Mock Data\"].json[\"a\"][\"b\"][\"c\"]}}"
            },
            {
              "name": "c2",
              "value": "={{$json.a.b.c}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    }
  ],
  "connections": {
    "Mock Data": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope that helps. If not, please try to give another example that I maybe understand better. Thanks!