Generating a login email via API

I’m looking to trigger the sending of a passwordless login email to a user from the API (that they would get if they hit ‘login by email’ themselves), and it doesn’t seem to be possible. I’ve used the ‘API reverse engineer’ technique to try and get at it, but authenticating with a global API key simply returns the homepage and triggers nothing (and without the api key it looks like it requires session cookies to be set etc.).

What I’m looking to achieve is a sign-up process with as few steps as possible; as users sign up through another system I create the users in Discourse, and I want them to get an email with the temporary login link to go straight in. This is all about reducing friction in a process that’s tedious enough!

Is there a trick to making this work through the API?

In this case the proper solution would be a invisible login setup using DiscourseConnect.

Have you tried:

curl -X POST https://meta.discourse.org/u/email-login \
-H "Api-Key: longapikeyhere" \
-H "Api-Username: system" \
--data-raw 'login=email%40gmail.com'

?

1 Like

Many thanks for the reply Falco. Specifically using curl exactly as you suggest I get a ‘You are being redirected’ response that would send me back to the home page. No login email is triggered. I was getting a similar result with the tool I was using - which was following the redirect back to the home page.

I don’t want to use DiscourseConnect as the only required login after signup is for Discourse.

Just also to add that, as a long-time user (and admirer) of Discourse forums this is my first foray into the other side - and the API / webhooks are just great; really easy to work with and very powerful.

2 Likes

That endpoint is not available for API calls at the moment indeed. When you pass API keys for it you fall on the redirect here:

And you can’t call it without API keys because this route is under the :verify_authenticity_token CSRF protection.

2 Likes

Thanks - that’s clear, and I can see the logic to it. Really appreciate the replies.

1 Like