Example code for adding email to a user account?

Hi,

I tried to follow the guidance provided below but I was getting 404 error response from stytch api.

Is there any code examples that I can copy/look at? I’m using email-password authentication method.

Thanks.

Hey Anggie,

Thanks for posting!

The most common reason for a 404 error when calling our otps/sms/send endpoint is that the request didn’t include a user_id , session_id, or session_jwt parameter, and the phone number doesn’t already belong to an existing user.

For context, the /send endpoint can either send an OTP to an existing Stytch user which already has the provided phone number associated with it (which doesn’t require the user_id or session parameters), or it can add a new phone number to an existing user (which does require the user_id parameter or a session parameter in order to know which Stytch user to associate the new phone number with).

If you’re looking to add a phone number to an existing user, you’d need to make a call that looks something like this (sample code with our backend Node SDK):

const params = { phone_number: "<phone_number_to_add>", user_id: "<existing_user_id_to_add_phone_to>" // alternatively, pass in session_id or session_jwt instead of user_id};client.otps.sms.send(params) .then(resp => { console.log(resp) }) .catch(err => { console.log(err) });

If you’re passing in a Stytch user_id to this call and still seeing 404 errors, would you mind sending over the relevant request_id for the error response? We can take a look at the logs on our end at that point to see what might be going on!

1 Like

Hi @matt-stytch , thanks for your reply. I got it working now.

Hey Anggie,

Awesome, glad to hear you got it working! Let us know if you have any further questions about this.