How to decode base64

Hi all

Describe the issue/error/question

Following a HTTP request, I get a JSON with loads of fields. The content of one of the fields that I need is encoded in base64. I have NO idea how to decode it! I am a noob in coding, so I have no idea how to use javascript or other to decode the base64. I was hoping maybe to find an API to decode the base64 field, but apart from it being a ridiculous workaround, I also didn’t find any such api services.

Can anybody please help me how to get this done?
I’ve just subscribed for the trial in the hope I can get n8n to work with my basic programming mindset, but minimal coding capacity. Please help me over this hurdle :slight_smile:

Please share the workflow

time trigger → http request → ?


Hi @bees8, welcome to the community!

Decoding base64 is a bit tricky in n8n, but possible. You’d need to run a bit of JS to do so. The basic approach is for example described here, in a workflow it would look like so:

In this example I am using the Function Item node which allows running arbitrary JS code. The example code adds a new memo_text field with the decoded value of each memo_base64 field in your transactions array:

Hope this helps!

Thanks so much for the reply @MutedJam !

I gathered I would have to use js, but no idea how!
Would you be able to fully paste the code you have used? Thanks!!

The code in my Function Item node is this one:

for (transaction of item.transactions) {
  // Create a buffer from the base64 string
  let bufferObj = Buffer.from(transaction.memo_base64, "base64");

  // Encode the Buffer as a utf8 string
  let decodedString = bufferObj.toString("utf8");

  // Write the result in a new memo_text field 
  transaction.memo_text = decodedString;

return item;

You can also just double click on the Function Item node in my example workflow above to see it (or simply copy the node directly into your own n8n canvas).

1 Like

Thanks again for your reply :slight_smile:

I’m getting the error “ERROR: item is not defined [Line 1]”

I’ve got a feeling the solution is super easy (defining ‘item’) :sweat_smile:

Are you by any chance using the Function node instead of the Function Item one?

ahhhh, got it, thanks!! It is working now :slight_smile:

1 Like