Utterly confused about how to bind the output of FunctionItem to the body of an HTTP Request

This strikes me as something that’s common and flexible, yet I cannot find anything that intelligently explains how to do this. Is this even possible?

You can do it using expressions. Can you share an example of the body you want to send so that I can put together an example workflow?

My dev environment is on another machine, so it’s hard to move between the two.

I’m looking at this video (n8n Nodemation basic - transforming json (3/3) (Tutorial) - YouTube) and it shows the body expression of an HTTP Request having an “Input Data” under the “Current Node”

My HTTP Request doesn’t have that. It just has “Parameters”

Plus why does the Body parameter even need a name if I’m just sending the entire JSON as a string?

The tutorial video of these two nodes has no relationship to the current version of N8N at all.

Here’s the workflow that creates this outcome:

{
  "name": "Good luck getting this highly opinionated implementation of basic stuff to work",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "6d390ffe-1396-4195-9cbd-82556e3068b4",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        90,
        470
      ],
      "webhookId": "6d390ffe-1396-4195-9cbd-82556e3068b4",
      "notesInFlow": true,
      "notes": "Roooo"
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://localhost:30/hooks/bloo/blee",
        "allowUnauthorizedCerts": true,
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "value": "="
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        570,
        460
      ]
    },
    {
      "parameters": {
        "functionCode": "// Code here will run once per input item.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.functionItem\n\n// Add a new field called 'myNewField' to the JSON of the item\nconst result = {\n  \"alias\":\"sigh > \",\n  \"text\":\"bet this will not work\",\n  \"attachments\":[{\n    \"title\":\"Twitter\",\n    \"title_link\":\"https://www.twitter.com\",\n    \"text\":\"Dumb Twitter\",\n    \"color\":\"#FF0000\"\n  }]\n};\n\nreturn result;\n"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        330,
        460
      ]
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FunctionItem": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "id": 2
}

You do not need to provide a key if you set JSON/RAW Parameters to true

image

Check the example below. I assumed that you want to send the output of the function item node as it’s.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://localhost:30/hooks/bloo/blee",
        "allowUnauthorizedCerts": true,
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "={{ $node[\"FunctionItem\"].json }}"
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        770,
        610
      ]
    },
    {
      "parameters": {
        "functionCode": "// Code here will run once per input item.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.functionItem\n\n// Add a new field called 'myNewField' to the JSON of the item\nconst result = {\n  \"alias\":\"sigh > \",\n  \"text\":\"bet this will not work\",\n  \"attachments\":[{\n    \"title\":\"Twitter\",\n    \"title_link\":\"https://www.twitter.com\",\n    \"text\":\"Dumb Twitter\",\n    \"color\":\"#FF0000\"\n  }]\n};\n\nreturn result;\n"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        530,
        610
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FunctionItem": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks, but this doesn’t work for me either. I also have the N8N_LOG_LEVEL set to debug and I cannot see any JSON or data in the logs to suggest my data is being sent out via the HTTP Request Axios call.

I’ve decided the HTTP Request has heavy options and the expression builder is kinda poorly documented, so I just made a Function node with the HTTP request helper and found exactly the reason for the problem I was having.

Please spend time creating meaningful tutorials regarding the expression builder. On its surface, it is clunky and unwieldy and can use some smooth guidance to ease people into how to solve problems with it. Other than that, great product here!

1 Like

Good to hear that you found a solution.

Improvements to the expression editor are in our roadmap.

2 Likes