Désabonner un utilisateur de tous les e-mails via un appel API ?

The site I maintain uses Discourse via SSO. When a user of my site unsubscribes from site generated emails, I would also like to unsubscribe the user from Discourse emails. It should be possible to determine what is required by looking at the API calls that are made when user email settings are changed via the UI, but I was wondering if there is an easier way?

1 « J'aime »

Will it always be the case that they don’t want to see site emails and community emails?

If the possibility exists that they will want to opt out of one and not both why not simply link to a page where they can manage their email preferences for discourse?

3 « J'aime »

Yes. Management has told me to unsubscribe users from discourse email when the user unsubs from site emails.

1 « J'aime »

For anyone interested in a follow up:
My need was met by following the reverse engineering guide. It was a fairly straight forward process to collect the contents of the PUT payload.

in Ruby, the payload I ended up with is:
payload = {mailing_list_mode: false, mailing_list_mode_frequency: 1, email_digests: false, email_in_reply_to: false, email_messages_level: 2, email_level: 2, email_previous_replies: 2 }

the ‘mailing_list_mode_frequency’ can probably be excluded since mailing_list_mode is false.
The payload is then PUT to https://DISCOURSEHOST/u/USERNAME.json?api_key=DISCOURSE_SYSTEM_API_KEY&api_username=system

7 « J'aime »

J’ai implémenté la même logique, mais les valeurs ne sont pas prises en compte dans les préférences e-mail des utilisateurs du site web.

Notez que la méthode consistant à passer api_key et api_username via les paramètres de requête est désormais obsolète ; vous devez utiliser les en-têtes Api-Key et Api-Username de nos jours.

1 « J'aime »