Forum Academy Marketplace Showcase Pricing Features

Error running Axios in Bubble plugin action

In my plugin, I’m using Axios to trigger a function in Firebase (which is similar to Lamdas in AWS). The reason I’m doing this in a plugin action rather than using an API call feature in the plugin builder is that I need to do some processing before hitting the API, and the API call feature times out too quickly (but mainly the first reason).

Here’s the relevant bit of code:

let data = {
body: json
}
let results = await axios.post("[function URL", data ); console.log(results.data);
return { jsonstring: JSON.stringify(results.data) }

However, when doing this, I keep getting this error in the logs on Bubble:
Workflow error - Plugin action Start selection - Adept Pumps Server Side (testing) error: AxiosError: Request failed with status code 400 at settle (/var/task/node_modules/axios/dist/node/axios.cjs:1909:12) at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/dist/node/axios.cjs:2989:11) at IncomingMessage.emit (node:events:526:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

When I use the exact same data with Postman to test the endpoint, it works fine, it’s just not working in Bubble. Is there something Bubble is doing here behind the scenes that could be screwing up this functionality?

Any ideas are appreciated, thank you!

If you use axios.post then data is your body object where you want to put all your parameters.
In your code you are adding the request payload all in a property called body, I suppose your endpoint is expecting something like {prop1:"", prop2:""} not {body: {prop1:"", prop2:""}}

1 Like

Thanks, I looked up the documentation and looks like you’re right, so I updated it. Still getting the error when running for some reason, but the script I’m calling seems to be kicking off, which is odd.

Do you know if there’s anything Bubble might be doing behind the scenes that might shut down an axios call in a plugin action? Or maybe not waiting for the the response to come back? I’m concerned if there’s something like that I’ll just be banging my head against a wall with this and I do that enough already!

400 is a bad request, are you 100% sure the body of the request is correct?