This is very frustrating. I’m trying to do a POST request to Salesforce whenever user registers via email.
I created an Action for this, put it into the post-registration flow but it’s simply not working. There are 3 other Actions and those are working just fine.
If I try to hit the Salesforce endpoint with Postman it works. If I open the Action and try to test it, it also works - I can see new Salesforce item added and even console.log
show I got 200
response.
However if I try to use this either from Auth0 Getting started page → try it out (or if I use my application which is using Auth0) the action will simply fail to create new records in Salesforce.
How can this be possible? If you run Test in the Action it works, but when trying live call it doesn’t? Even more frustrating is that you have no way of knowing what’s wrong, since there are no logs for the actions.
I have axios@0.24.0
in the Modules and also the secret is there and it’s correct URL. Below is the code:
const { URL } = require("node:url");
const axios = require("axios");
/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the context and user that has registered.
*/
exports.onExecutePostUserRegistration = async (event) => {
try{
let url = new URL(event.secrets.SALESFORCE_FORM_URL);
url.searchParams.set('email', event.user.email ?? '');
url.searchParams.set('first_name', event.user.given_name ?? '');
url.searchParams.set('last_name', event.user.family_name ?? '');
url.searchParams.set('company', event.user.user_metadata.company ?? '');
url.searchParams.set('visitor_id', event.user.email ?? '');
url.searchParams.set('status', 'Active');
const response = await axios.post(url.href);
if(response.status === 200){
console.log('Salesforce called');
console.log(response);
}
}catch(e){
console.log(e);
}
};
Can somebody help me with this? Or give me at least hints how to troubleshoot this?