# I need to get the RAW body from a listener node

**URL:** <https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105>\
**Category:** General\
**Created:** [13 September 2018 09:10 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105 "2018-09-13T09:10:32Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![chrisnie](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@chrisnie](https://discourse.nodered.org/u/chrisnie)\
**Post date:** [24 October 2018 11:11 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/21 "2018-10-24T11:11:43Z")

</div>

Hi @knolleary  
I already started extending the `21-httpin.js` with an additional option to expose the rawBody (same concept with the body-parser's verify function) but it didn't work. The current solution works just by modifiing the `settings.js` so no patching of Node-RED itself was necessary. But when you have a way / idea how to deal with the admin interface i could make out a PR out with my extensions...

Cheers, Chris

---

<div class="post-metadata">

**Author:** ![Toastgeraet](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@Toastgeraet](https://discourse.nodered.org/u/Toastgeraet)\
**Post date:** [29 June 2020 07:53 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/22 "2020-06-29T07:53:00Z")

</div>

Some late praise @chrisnie, great work! Exactly what i was looking for. Also the use case of verifying sha256-hmac of the request, for auth purposes. In the mean time, has any progress been made integrating this into NodeRED proper @knolleary?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [29 June 2020 07:56 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/23 "2020-06-29T07:56:48Z")

</div>

> [@Toastgeraet](#):
>
> has any progress been made integrating this into NodeRED proper @knolleary?

No - this dropped off my radar and no-one else picked it up.

---

<div class="post-metadata">

**Author:** ![Toastgeraet](https://avatars.discourse-cdn.com/v4/letter/t/e480ec/32.png) [@Toastgeraet](https://discourse.nodered.org/u/Toastgeraet)\
**Post date:** [29 June 2020 12:20 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/24 "2020-06-29T12:20:09Z")

</div>

Alright, thx for the update!

---

<div class="post-metadata">

**Author:** ![alexk111](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexk111/32/16891_2.png) [@alexk111](https://discourse.nodered.org/u/alexk111)\
**Post date:** [14 August 2020 14:28 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/25 "2020-08-14T14:28:43Z")

</div>

One more vote for the raw body option in http in nodes. Having the same issue with the request verification.

---

<div class="post-metadata">

**Author:** ![srk78](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/srk78/32/58444_2.png) [@srk78](https://discourse.nodered.org/u/srk78)\
**Post date:** [14 March 2022 10:36 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/26 "2022-03-14T10:36:37Z")

</div>

Another bump for this functionality. Request verification for webhooks fired from WooCommerce is also done by a hmac-SHA256 checksum over the body with a shared secret.

---

<div class="post-metadata">

**Author:** ![MarkPartlett](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/markpartlett/32/49197_2.png) [@MarkPartlett](https://discourse.nodered.org/u/MarkPartlett)\
**Post date:** [29 May 2022 07:15 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/27 "2022-05-29T07:15:34Z")

</div>

A bump for this functionality from me too. I’m trying to use the rawBody for validation of the Nextcloud webhooks app : [GitHub - kffl/nextcloud-webhooks: Webhooks app for Nextcloud](https://github.com/kffl/nextcloud-webhooks) using SHA256.

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [22 June 2022 14:30 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/28 "2022-06-22T14:30:37Z")

</div>

> [@chrisnie](#):
>
> After discovering this line 36 gave me the right hint: We just get the admin UI away form the default path by setting something like `httpAdminRoot: '/admin',` in `settings.js` and voila - the request is unparsed in `httpNodeMiddleware`.

@chrisnie Did not work for me. I am still getting parsed body

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [22 June 2022 14:32 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/29 "2022-06-22T14:32:20Z")

</div>

> [@chrisnie](#):
>
> As next step I've created an own jsonParser setting me the raw body. I've also placed this code into `settings.js` just before the `module.exports = {` line:

Added that and now node red won't load

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2022 15:02 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/30 "2022-06-22T15:02:06Z")

</div>

You may have a syntax error in settings.js. What error do you see when you try to start node red?

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [22 June 2022 17:01 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/31 "2022-06-22T17:01:02Z")

</div>

# Step 1: Identify current state

`node-red` before starting anything

```auto
22 Jun 16:39:41 - [info] Node-RED version: v2.2.2
22 Jun 16:39:41 - [info] Node.js version: v12.22.12
22 Jun 16:39:41 - [info] Linux 5.13.0-1031-aws x64 LE
22 Jun 16:39:41 - [info] Loading palette nodes
22 Jun 16:39:42 - [info] Settings file : /home/ubuntu/.node-red/settings.js
22 Jun 16:39:42 - [info] Context store : 'default' [module=memory]
22 Jun 16:39:42 - [info] User directory : /home/ubuntu/.node-red
22 Jun 16:39:42 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Jun 16:39:42 - [info] Flows file : /home/ubuntu/.node-red/flows.json
22 Jun 16:39:42 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

22 Jun 16:39:42 - [error] Unable to listen on http://127.0.0.1:1880/
22 Jun 16:39:42 - [error] Error: port in use

```

Note I am not using the default port

# Step 2: Enable httpNodeMiddleware

```auto
    httpNodeMiddleware: function(req,res,next) {
    // // Handle/reject the request, or pass it on to the http in node by calling next();
    // // Optionally skip our rawBodyParser by setting this to true;
       req.skipRawBodyParser = true;
       next();
    },

```

...restart node red `pm2 restart node-red`

`node-red` provides same result

Running a flow with http in... input still parsed object

 ![Screenshot 2022-06-22 at 19.47.48](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f0b3dc1f1a33bfe840f0b6f5fb4ec93b6a823268.png)

# Step 3: Change the admin panel from [my.domain.com](http://my.domain.com) to [my.domain.com/admin](http://my.domain.com/admin)

in settings.js, just enabled the

`httpAdminRoot: '/admin',`

... restart node red `pm2 restart node-red`

and check `node-red`

The terminal output is now different

```auto
22 Jun 16:51:47 - [info] Node-RED version: v2.2.2
22 Jun 16:51:47 - [info] Node.js version: v12.22.12
22 Jun 16:51:47 - [info] Linux 5.13.0-1031-aws x64 LE
22 Jun 16:51:48 - [info] Loading palette nodes
22 Jun 16:51:48 - [info] Settings file : /home/ubuntu/.node-red/settings.js
22 Jun 16:51:48 - [info] Context store : 'default' [module=memory]
22 Jun 16:51:48 - [info] User directory : /home/ubuntu/.node-red
22 Jun 16:51:48 - [warn] Projects disabled : editorTheme.projects.enabled=false
22 Jun 16:51:48 - [info] Flows file : /home/ubuntu/.node-red/flows.json
22 Jun 16:51:48 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

22 Jun 16:51:48 - [error] Unable to listen on http://127.0.0.1:1880/admin/
22 Jun 16:51:48 - [error] Error: port in use

```

Catching a new webhook... msg.payload is again an object

 ![Screenshot 2022-06-22 at 19.54.20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/8365939760b2abd49f26b4d6ba7fe52badf03565.png)

After changing the root directory, I also get a 404 error from Postman. The error is due to cryptojs library I manually added in node red. I assume the library cannot be accessed from the /admin directory

# Step 4: Try the adding the code

## Coded Added

```auto
var bodyParser = require('body-parser');
var jsonParserWithRawBody = bodyParser.json({
    verify: function (req, res, buf, encoding) {
        req.rawBody = buf;
    }
})

```

in the very beginning - just above module.exports

## Coded removed

Commented out the httpNodeMiddleware that I enabled in Step 2 and added the code above instead

```auto
httpNodeMiddleware: function(req,res,next) {
        if (req.url === '/my/httpin/url/where/i/want/to/have/the/raw/body') {
           jsonParserWithRawBody(req, res, next);
        } else
           next();
    },

```

...restart ... `node-red`

Error loading settings file: /home/ubuntu/.node-red/settings.js  
ubuntu@ip-172-31-32-243:~$

Nothing works, I am exhausted

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2022 17:18 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/32 "2022-06-22T17:18:22Z")

</div>

> [@stathisaska](#):
>
> `Error: port in use`

You have to stop the current node red instance from running before you start another one.

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [22 June 2022 17:31 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/33 "2022-06-22T17:31:16Z")

</div>

@Colin

I restarted the server and I am getting the same error. Maybe pm2 ? Is this relevant to the issue ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2022 17:58 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/34 "2022-06-22T17:58:31Z")

</div>

If the port is already in use then almost certainly node red is already running.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [22 June 2022 18:03 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/35 "2022-06-22T18:03:20Z")

</div>

The settings.js error means you have messed it up. Restore the previous version from your backup and start again.

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [22 June 2022 22:09 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/36 "2022-06-22T22:09:26Z")

</div>

Ok will try starting from scratch

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [23 June 2022 10:25 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/37 "2022-06-23T10:25:40Z")

</div>

@Colin Getting the same error on Ubuntu 20.04.4 LTS

The error appeared after installing pm2

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 June 2022 11:58 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/38 "2022-06-23T11:58:37Z")

</div>

Which error exactly?

---

<div class="post-metadata">

**Author:** ![stathisaska](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@stathisaska](https://discourse.nodered.org/u/stathisaska)\
**Post date:** [23 June 2022 22:04 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/39 "2022-06-23T22:04:21Z")

</div>

I could not make this work. I highly discourage anyone trying it as it turned out an outrageous amount of time waste for me.

I used n8n instead

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 August 2022 22:04 UTC](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105/40 "2022-08-22T22:04:29Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/i-need-to-get-the-raw-body-from-a-listener-node/3105.md?page=1)
