Post-registration action with Salesforce not working for "live" calls

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?

After couple of hours of trial and error I discovered that event.user.family_name nor event.user.given_name are not available and therefore it was silently failing.

I changed the Login form to put these values into user_metadata instead. So now I have this url.searchParams.set('first_name', event.user.user_metadata.first_name ?? 'Unknown'); and with this it is now working as it should.

1 Like

Thanks for sharing it with the rest of community!