How do I pass data through Axios?

I’m using passing a command from Google sheets though Axios to my url.

How would I format this Axios template to incorporate a step with data?
I’ve looked all over and can’t figure it out.

Step
(steps.trigger.event.body.Function)

Axios Template-

import axios from “axios”

export default defineComponent({
async run({ steps, $ }) {
console.log(steps.trigger.event.payload_raw)

const { data } = await axios({
  method: "POST",
  url: "https://httpdump.io/sejhw",

})
return data
},
})

Hi @lavellladishmon , thanks for reaching out. Take a look at this example from our docs. You’ll want to pass the data in the data field of the axios request.

1 Like

@dylan Perfect !!
But I forgot to mention that I’m passing data from
(steps.trigger.event.body)
I can’t seem to find the correct format for that in any of the examples.

Hi @lavellladishmon

You can use Step Exports to connect steps together.

Here’s a short video on how to do that in Node.js code steps: Passing props to code steps - YouTube

In your case, the payload_raw attribute is available under steps.trigger.body.payload_raw.

Here’s another example in our documentation: Writing Node.js in Steps

@pierce I was able to create the prop but still unable to pass the prop through my post command to my end url. I’m guessing it’s a formatting issue? The prop should be called somewhere under the POST and URL right? (not console logged)

Hi @lavellladishmon

Nice use of props by the way, and you’re very very close.

But take a look at that request reference in the axios documentation, the data argument does not support a string argument:

  // `data` is the data to be sent as the request body
  // Only applicable for request methods 'PUT', 'POST', 'DELETE', and 'PATCH'
  // When no `transformRequest` is set, must be of one of the following types:
  // - string, plain object, ArrayBuffer, ArrayBufferView, URLSearchParams
  // - Browser only: FormData, File, Blob
  // - Node only: Stream, Buffer
  data: {
    firstName: 'Fred'
  },

this.email is a string, so you need to pass it as an object:

data: {
   email: this.email
}

@pierce
You’re the best !!

1 last thing.

It came through with the prefix attached. Is there a way to get rid of the (“payload”) in the delivery?

Thanks so much. The videos are great !!

Great, happy to hear @lavellladishmon

I believe this is the step above according to your post before: How do I pass data through Axios? - #5 by lavellladishmon

I’m not totally sure what you’re trying to accomplish with the payload prop. Are you trying to just pass the entire body from the incoming HTTP request to your webhook to Helium?

Yes. I’m trying to pass only the body details through.

It looks like its passing both the Prop’s name and it’s contents. I just need the contents without the prop name.

Helium is looking for a single sting that will execute a command on Helium’s end.

Thanks for the details, but could you please share the link to the specific documentation of the endpoint you’re trying to integrate with?

This what helium has for receiving data from another location.

Thanks, I think it’s finally clicking for me.

You’re trying to emulate these fields specifically I believe: JSON Schema | Helium Documentation

They have a helpful Postman screenshot to help you design your JSON structure:

In your case, you need to make an object containing a payload_raw, port, and confirmed.

It looks like you’ve base64 encoded the payload_raw string, which is good. But you may need to define the other keys in the object that Helium is expecting.

Is there a way to pass data through besides using Props?

Yes, you can use Step Exports instead.

I encourage you to try the HTTP request builder action instead of a Node.js action for your case, it might be easier for you to follow along that Helium’s Postman example for sending a downlink request.

Awesome !! I was able to get it to work through http. Much easier !!

I’ll post the entire process once I get the final version up and running.

1 Like

Great happy to hear :slight_smile:

Yes, please do share, I don’t know much about Helium and curious to see what you built!