Axois get call post login

How would I write an axios call to a get endpoint in the post-login actions? I tried this but it was giving me a 404 (I’m able to plug in the same headers and url in postman and get data back)

exports.onExecutePostLogin = async (event, api) => {
  const axios = require('axios');
  
  const namespace = '****';

  const url = 'https://*******/user-info';
  const options = {
    headers: {
      'Authorization': '****',
      'Inst2Person' : '****'      
    }
  };
  var response = await axios.get(url, options);
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/responseFromApiIDToken`, response.data.****);
  );
  }
};

Hi @jared.modugno,

Thanks for reaching out to the Auth0 Community!

After looking carefully at the code snippet you shared, it looks like you are calling an endpoint that does not exist. (Reference: Authentication API Explorer)

The correct endpoint should be /userinfo without a hyphen.

Could you please make these changes and let me know how it goes?

Thanks,
Rueben

Apologies, the endpoint i’m trying to hit is an api that I’ve created that ends in user-info. It’s an endpoint that hosted (it doesn’t use my localhost).
Does the rest of the axios call look correct?

1 Like

It was a proxy issue with the api on my side, thank you for your response!

1 Like

Hi @jared.modugno,

I’m glad you got it working now!

Please let us know if there’s anything else we can do to help.

Thanks,
Rueben

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.