Is there a way to change or delete the secondary email

Hi,

I searched here and in the API docs, but I can’t see any way to affect the secondary email. My primary need is to delete it, but we may want to change it as some point.

Thanks in advance,

Mark

The easiest way to figure out how to make an API request to remove the secondary email would be to create a test user with a secondary email address, then remove the email address through the UI with your browser’s inspector opened to its Network tab. That method is outlined here: How to reverse engineer the Discourse API.

It looks like you need to make a DELETE request to /u/<discourse_username>/preferences/email.json

The email you are wanting to delete should be passed as form data. For example, email=simon%40foo.com

1 Like

Thanks Simon,

I actually knew this, but for some reason, I hit the wrong “wrench” on the User Profile, and it didn’t show me the delete option. Once had the correct option I inspected it found what I needed. I tried it in Postman, it worked!

The curl for this is:

curl --location --request DELETE 'https://[discourse_url]/u/[discourse_user_name]/preferences/email.json?email=[address_to_delete]' \
--header 'Api-Key: [your_api_key]' \
--header 'Api-Username: system' \
--header 'Content-Type: application/json' 

Updated to add: Don’t forget to URL encode the email address. The API will respond with “success”: “OK”, but it won’t actually delete the address if you don’t do this.

Mark

3 Likes