Create staged users via API?

I’m kicking around the idea of building a webhook+api bridge service to connect given categories on two different discourse forums. The rough idea would be:

  1. A webhook on each server for Topic and Post events[1]
  2. A listener which takes these and replicates the event on the opposite server via the API
    • Uh, something to prevent loops, obviously[2]
    • Check if a user with the same email address exists on the opposite server[3]
    • If no such user exists, create a staged user
    • Change the staged user’s notification settings so they don’t get email notifications[4]
    • Create or update the post under the appropriate real or staged user
  3. Probably a timed routine to go through topics and make sure nothing was missed, and possibly reorder so both sides agree

From Understanding user statuses, roles, and permissions, I think that staged users would basically do what we want – if someone did create an account with that email address later, they could “claim” it and interact with all their posts just as if they’d been there all along.

But, is there a way to create a staged user from the API? I don’t see that in Discourse API Docs.


  1. and possibly also Like and Solved events, but not in the first cut ↩︎

  2. I definitely thought about this before writing out this list ↩︎

  3. using email addresses as key because account systems may not have same usernames ↩︎

  4. I saw a post about this being possible somewhere around here… ↩︎

Not sure if this is what you want?

3 Likes

Well, kind of. As the OP in that topic says, in reply to that…

… and there, the answer is to basically inject an email and let the email handling code take care of it. But, that doesn’t work for this case, because I need to intervene and turn off email notifications for the user before creating the post.

It happens that we have SSO-overrides-username turned on for one side of the proposed bridge, so I think just creating something like ‘othersite-user’ could be a workaround… but that won’t necessarily work without that SSO setting.

If passing staged: true to the admin user create call doesn’t work, I suspect we’d be open to a PR to enable that.

(It’s somewhat of a niche feature outside of your use case I think?)

Perhaps you could use the handle_mail route to post a fake email as the user? (Oh, as @blake suggests)

That would create the staged user if necessary and the topic at the same time.

2 Likes

With this approach it’s going to look as though users have created topics and replies via email. Staged users can only create posts via email. You’ll get an invalid access error if you attempt to create a non-email post for a staged user via the API.

Something about the staged user approach doesn’t feel quite right to me. It might be worth polling your users to see if they have any concerns. If you could get permission from your users, you could just create active non-staged users on the mirror site, then post their topics and comments via the API.

Passing staged: true creates a staged user. I’m assuming a user created in this way will be able to post via email. My local dev site isn’t configured to send emails to Discourse, so I can’t test that at the moment.

1 Like

I’ve been wanting to use discourse as a generic form processor to handle contact forms. I hate contact forms, but some users would rather use a contact form them than send an email. Even if I think those people make bad decisions, I’d like to make it easier for them to contact me so they can give me money.

It would be really handy to be able to create a message that creates a staged user without having to resort to some other system to process the form and send an email.

I assume I’ll need to create a plugin to do this, but that’s my plan.

This is one of the only things I have left to figure out to get rid of wordpress.

So maybe what I’ll do in the plugin is create the post as if it were an email. That might not be too hard on a plugin. And that would likely make it possible via am api.

2 Likes

I reckon that you could use a Wizard (:mage: Custom Wizard Plugin) to achieve that without too much bother. You can do anon wizards now. Happy to give you a hand if needed!

3 Likes

Yes, this works: Creating a staged user with an API call - #8 by blake.

1 Like

Oh! Of course. That’s how the mail-receiver delivers mail. I think I want an endpoint that will accept arbitrary fields from whatevver form, stick them into a topic, and deliver them to me. That would keep me from having to make public an API key (scoped to just deliver mail it doesn’t seem that horrible, to have javascript process the form and then deliver it to the existing endpoint).

1 Like