Magic Links

Send a magic link to an existing Stytch user using their email address. If you'd like to create a user and send them a magic link by email with one request, use our log in or create endpoint.

Add an email to an existing user

This endpoint also allows you to add a new email address to an existing Stytch User. Including a user_id, session_token, or session_jwt in your Send Magic Link by email request will add the new, unverified email address to the existing Stytch User. If the user successfully authenticates within 5 minutes, the new email address will be marked as verified and remain permanently on the existing Stytch User. Otherwise, it will be removed from the User object, and any subsequent login requests using that email address will create a new User.

Next steps

The user is emailed a magic link which redirects them to the provided redirect URL. Collect the token from the URL query parameters, and call Authenticate magic link to complete authentication.

post/v1/magic_links/email/send

Request

  • Base URL
    https://api.stytch.com
  • Auth
    HTTP basic

Request body

emailstring required

The email address of the User to send the Magic Link to.

login_template_idstring

Use a custom template for login emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Login”.

login_magic_link_urlstring

The URL the end user clicks from the login Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and log in the User. If this value is not passed, the default login redirect URL that you set in your Dashboard is used. If you have not set a default login redirect URL, an error is returned.

signup_magic_link_urlstring

The URL the end user clicks from the sign-up Email Magic Link. This should be a URL that your app receives and parses and subsequently send an API request to authenticate the Magic Link and sign-up the User. If this value is not passed, the default sign-up redirect URL that you set in your Dashboard is used. If you have not set a default sign-up redirect URL, an error is returned.

login_expiration_minutesinteger

Set the expiration for the login email magic link, in minutes. By default, it expires in 1 hour. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).

signup_expiration_minutesinteger

Set the expiration for the sign-up email magic link, in minutes. By default, it expires in 1 week. The minimum expiration is 5 minutes and the maximum is 7 days (10080 mins).

code_challengestring

A base64url encoded SHA256 hash of a one time secret used to validate that the request starts and ends on the same device.

user_idstring

The unique ID of a specific User. You may use an external_id here if one is set for the user.

session_tokenstring

The session_token of the user to associate the email with.

session_jwtstring

The session_jwt of the user to associate the email with.

locale'en' | 'es' | 'pt-br' | 'fr'
signup_template_idstring

Use a custom template for sign-up emails. By default, it will use your default email template. Templates can be added in the Stytch dashboard using our built-in customization options or custom HTML templates with type “Magic links - Sign-up”.

Response

Successful response

request_idstring required

Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.

user_idstring required

The unique ID of the affected User.

email_idstring required

The unique ID of a specific email address.

status_codeinteger required

The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.

Changes