Adding user data to external database via Curl (POST) works, but fails using Auth0's Action (Axios POST)?

Hello, friends!

I am attempting to utilize an Auth0 Action to set up a POST call whereby after a user logs in on my webapp (in this case using LinkedIn), their email address is automatically passed to an external PostgreSQL database that I control. I set up the PostgresQL database and have tested POST actions to it using a cURL command, which works perfectly fine:

curl --data “email=sampleEmail@gmail.comhttp://aaa.ngrok.io/users

However, when using an Axios call via Auth0 action in test mode, I cannot get things to work. I always get the error:

“error: null value in column “email” of relation “users” violates not-null constraint”
detail: ‘Failing row contains (null).’,

… and then my PostgresQL database crashes.

I have searched online and tried almost everything I can think of, including adding headers to Axios, and playing around with variations of the code, but nothing seems to work.

Does anyone have any idea why a cURL POST request would work but an Axios call via Auth0 Actions wouldn’t ? For reference, here is my Axios Action POST call below (which should be triggered after a successful login, but this is irrelevant since the call doesn’t even work under manual test conditions?):

const axios = require(“axios”);

exports.onExecutePostUserRegistration = async (event) => {

const body = { email: event.user.email }

await axios.post(“http://aaa.ngrok.io/users”, body);
};

Thanks and Best,

As follow up, I have gone through the ins and outs of several variations of the Action code provided by Auth0. I even changed it around so that it is not POSTing anything from the sample Event JSON Object, but instead just a simple text string (i.e. "John@email.com’). Still fails, while my cURL POST commands to the same database, on the other hand, work just fine.

Therefore, is it possible that the error pertains to a firewall issue, or even a CORS issue? For reference, I am based in China, and have no problem accessing the Auth0 website, even without a VPN. Then again, the issue doesn’t seem to be that the Axios call isn’t reaching my local database, but rather that no value is getting passed through…?

Re-examining the Axios.POST call I posted above, I just noticed that the database’s table name is never specified! Therefore, there is confusion when the local database receives the data; it doesn’t know which table to insert the data into? Users? Products?

Even though it’s quite obvious when one takes a distant view of it; I’d recommend that in the future, auth0’s Action documentation to include where and how to specify the table the user is querying… Could be helpful for other noobs like myself…? Thanks and have a great day!

1 Like

Hey there!

As this topic is related to Actions and Rules & Hooks are being deprecated soon in favor of Actions, I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

Learn more here!