How to Access Response Headers Using '@pipedream/platform axios'?

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

Hi all. When using @pipedream/platform axios how can I get access to the response headers?

Normally with Axios I can use the (e.g.) response**.data** and response**.headers** objects.

The Pipedream version seems to put the body directly into response and there seems to be no headers available to work with?

When using @pipedream/platform axios, you can access the response headers by setting the returnFullResponse property to true in the axios config object. This will return the full axios response object, which includes the headers. Here’s an example of how you can do it: import { axios } from "@pipedream/platform"; export default { async run() { const response = await axios(this, { url: "https://httpbin.org/get", returnFullResponse: true, // This line is important }); console.log(response.headers); }, }; In this example, the console.log(response.headers); line will log the headers of the response.

recall that in Pipedream code steps, $ is destructured in the run method and $ is passed as the first argument of the axios call

Yes, you’re correct. In Pipedream code steps, the $ object is passed as the first argument to the axios call. This is because the axios method from @pipedream/platform uses methods provided by the $ object. Here’s an example: import { axios } from "@pipedream/platform" export default { async run({ $ }) { const response = await axios($, { url: "https://httpstat.us/200", returnFullResponse: true, // This line is important }); console.log(response.headers); }, }; In this example, the console.log(response.headers); line will log the headers of the response. The returnFullResponse: true line ensures that the full axios response object, including headers, is returned.

let me know if that works. Setting that param should be the correct way to return the full axios response and access headers

Thanks and @U05A7KLNALC, good bot!

You’re welcome! If you have any more questions or need further assistance, feel free to ask. Happy coding!