Help with Axios request

Hello,

I’m trying to run the following NodeJS step and getting an error message.

import { axios } from "@pipedream/platform";
import querystring from "querystring";

export default defineComponent({
  async run({ steps, $ }) {
    const { response } = await axios({
      url: "https://app.kartra.com/api",
      method: "POST",
      headers: {
        "Content-Type": "application/x-www-form-urlencoded",
      },
      data: querystring.stringify({ 
        app_id: "id_here",
        api_key: "key_here",
        api_password: "password_here",
        cmd: "edit_lead",
        email: steps.get_record.$return_value.fields.buyer_email,
        last_name: "doe"
        }),
    });

    return response;
  },
})

The error I’m getting is:

TypeError
Cannot read property 'headers' of undefined

I’m really confused because I’m passing the headers as part of the POST request.

Solved… I needed to add the $ object to axios:

await axios( $, {
1 Like