Body payload as binary data from webhook

Hello,

I have a webhook that provides me with a body in JSON form. For authentication the manufacturer provides a signature code. This is calculated with crypto. The calculation needs the raw data of the body.

My problem with the calculation is that the internal conversion to JSON will result in a change of the content. See the example:

“fNumber”:8.0, → becomes “fNumber”:8,

I think I have already tried everything, but I can’t get the raw data into the value field of crypto. These are my tests:

  • {{JSON.stringify($json[“body”])}} → convert issue 8.0 becomes 8
  • {{$binary.data}} → it is not the data content it is: [Object: {“mimeType”:“application/json”}]
  • Move Binary Data - Modul → same converting error.
  • Set Webhook with Option “Binary Data”, the hook is not triggered. Only when i set the option to “Raw Data”. (“content-type”: “application/json”)

How can i get the original raw data from the Body of the Request to put it into the Value from Crypto?

Information on your n8n setup

  • **n8n version:latest on-premise
  • **Database you’re using (default: SQLite):SQLite
  • **Running n8n with the execution process [own(default), main]:own
  • **Running n8n via [Docker, npm, n8n.cloud, desktop app]:npm
1 Like

Hi @Hans_Wurst, first of all, welcome to the community :tada:

I’m sorry to hear you’re having trouble.

This would be because n8n is a Javascript application and there is no difference between 8.0 and 8 in JavaScript, both would be considered of type number. You will find the same behaviour outside of n8n as well (e.g. when typing console.log(8.0) in your browser console it prints 8). This is also reflected in JSON where no distinction between integer and floating-point types exists.

So to preserve the original value, you would need to work with - for example - a String instead of JSON. Would this approach work for you?

Example Workflow

When POSTing a JSON body to my webhook URL like this:
image

It was preserved all the way to the crypto node:

1 Like

Hi @MutedJam ,

this approach works great! The Destination Key did the trick!

Now i can access the raw data as string and crypto encrypt the right data.
Thank you very much.

PS: And i didn’t need the Set node or does this have another special feature that I do not know?

3 Likes

Awesome, glad to hear this works, thanks a lot for confirming!

I was in a rush when I shared the example and was first experimenting using the Set node - if it works without the Set node, just throw it away :smiley:

1 Like