How do I base64 decode data from my incoming HTTP payload?

This topic was automatically generated from Slack. You can find the original thread here.

Raoul Strachan : hi … I was wondering if someone could help? I’m new to pipedream and trying to get some json data from my iot sensor decoded from Base64. When I try https://pipedream.com/@dylburger/base64-decode-raw-http-payload-p_2gC7Py/edit

Dylan Sather (Pipedream) : happy to help. When you copy that workflow and send your base-64 encoded payload, did you encounter a specific error?

Raoul Strachan : when I run it I get: paramsData

{{steps.trigger.raw_event.body_b64}}

STRING ·params.data
code1

**async** params => {

}
const buffer = Buffer.from(params.data, ‘base64’);
this.data = buffer.toString(‘utf8’);

TypeError [ERR_INVALID_ARG_TYPE]The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
at Function.from (buffer.js:207:11)
at Object.module.exports (/steps/base64_decode_string.js:2:23)
at MessagePort.messageHandler (/opt/nodejs/node_modules/@pipedreamhq/execution-environment/launch_worker.js:339:41)
at MessagePort.emit (events.js:198:13)
at MessagePort.onmessage (internal/worker.js:84:8)

Dylan Sather (Pipedream) : would you mind sharing your workflow with dylan@pipedream.com?

Raoul Strachan : Thanks … I’ve shared it now :slightly_smiling_face:

Dylan Sather (Pipedream) : Thanks. It seems like the data arrive as JSON, actually. In the first step of your workflow (the HTTP trigger), if you click on a specific event on the left, do you see the body property? That contains the incoming HTTP payload. We parse the incoming JSON as a JavaScript object, so you can access its data in future steps using, for example, steps.trigger.event.body.name (to reference the name property).

Was there a specific property in the body that was base64-encoded that you’d like to decode?

Dylan Sather (Pipedream) : I see a payload field in the HTTP payload that appears to be base64-encoded - does that contain the data you need?

Raoul Strachan : hi … yes, that’s the data I’m trying to get. I basically want to decode it so I can parse it though python using pandas …

Raoul Strachan : when i click on an event on the left I’m not seeing a body property … but I could be looking in the wrong place :slightly_smiling_face:

Dylan Sather (Pipedream) :

Dylan Sather (Pipedream) : you can click on that, and it’ll expand to show you the full HTTP payload

Dylan Sather (Pipedream) : Do you see how the base64-decode step references the variable {{steps.trigger.event.bodyRaw}}? That variable doesn’t exist, which is why you get the error that it’s undefined. You’ll need to pass whatever variable you’d like to decode to that step, instead.

If you remove that value from the Data param, you’ll see an option to select other variables just below it. You can click into event, then body, then select the payload value from there:

Raoul Strachan : hmm … I thought it might be that but it won’t let me. Says I can’t edit in read-only editor …

Dylan Sather (Pipedream) : do you still have an event selected? When you select an event, we let you explore the logs / errors for that specific run, but you’ll need to de-select the event from the left first. Then, you should be able to edit the param.

Raoul Strachan : Aha … that’s brilliant. Thank you. That has been doing my head in for the past 2 hours :slightly_smiling_face:

Dylan Sather (Pipedream) : sorry you had so much trouble. We are planning to make some UX improvements here that should make this simpler!

Are you getting the decoded data now?

Raoul Strachan : right … well, I’ve seleted the right data now but it’s still giving the same error …

Dylan Sather (Pipedream) : did you happen to Deploy your changes (see the blue button at the top). If so, did you try sending a new event to the workflow after you made the change?

Raoul Strachan : should i be using ‘const string’ instead of ‘buffer’?

Raoul Strachan : yes … I’ve got the switch on green so it’s listening all the time