Obtenha endereço de e-mail de um usuário via API

Existe alguma maneira de obter o endereço de e-mail atual de um usuário via API?

Nosso caso de uso é o seguinte:

Permitimos que os usuários gerenciem suas informações do Discourse por meio do nosso site. Em geral, o Discourse é usado apenas como uma lista de e-mails e quase nenhum usuário visita o site real do Discourse. Gostaria de poder mostrar ao usuário o endereço de e-mail atual que o Discourse está usando, para que ele possa verificar se precisa ser alterado.

Conseguimos fazer isso com todos os outros campos, exceto o e-mail.

Antigamente, havia um endpoint de API users/{username}/emails, mas parece que ele não está mais disponível.

Hi,

GET /users/:username.json

will display the email in two cases:

  • the user id of the API KEY holder is the same than the user id related to the requested username
  • the API KEY holder is staff and the requested user is staged

Read more about this in code:

AFAIK this codepath has not changed recently.

Yeah, but that doesn’t help me. All of the users are already active and the user API key is not going to match.

This request does work for me:

curl "http://example.com/users/joffreyjaffeux/emails.json" \
     -H 'Api-Username: joffreyjaffeux' \
     -H 'Api-Key: xxx' \
     -H 'Content-Type: application/json; charset=utf-8' \

But, does it work if the URL is http://example.com/users/paulapostolos/emails.json ?

Yes it should work for yourself and other users as long as this is true:

  def can_check_emails?(user)
    is_admin? || (is_staff? && SiteSetting.moderators_view_emails)
  end

Note that doing so will trigger a staff action log.

That worked…I had some old code that used to work (version 1.4 ish) that had the request as a PUT and without the .json at the end. I modified it to a GET and changed the URL and now it works.

Thanks for the help!