You can send an invite through the Discourse API by making a POST request to https://forum.example.com/invites
In the body of the request you need to include the All Users api_key
and api_username
. The All Users api_username
defaults to ‘system’. The other parameter that you need to include is email
. You can optionally include a custom_message
and a group_names
parameter. The group_names
parameter should be set to a comma separated list (without spaces) of group names for groups that already exist on your forum.
Here is an example API call made with curl. $api_key
is set to the All Users API key for my forum. The URL is the URL of my local development forum:
curl -X POST -d "api_key=$api_key&api_username=system&email=johndoe@example.com&custom_message=Thanks for your contribution." http://localhost:3000/invites
The response you should get for a successful invite is {"success":"OK"}
.
Once you have this working with curl or Postman, it should be possible to wire up your application to make the request automatically when a user makes a contribution.
You can customize the email templates that are used for sending these invites. The template that is used if a custom message is included is the Custom Invite Forum Mailer template. The template that is used when a custom message is not included is the Invite Forum Mailer.
For details about finding which API request to make to perform a specific action, see the How to reverse engineer the Discourse API topic. For details about customizing email templates, see the How to customize email templates topic.