khill
7 years agoMentor
REST API V2 - Query email from users returns null value
Hi everyone, I am trying to make an API v2 call to return a list of user IDs and their email addresses. When I make the call the login returns correctly, but email field returns with no data. Any i...
- 7 years ago
Parshant is right, would you like your email to be accessible like that trough a public community URL =)?
You have two options (maybe more, but that's off the top of my head)
a) Do the OAuth flow with the public v2 API URL (the one you're using now)
or
b) Write a custom component that does the same thing, but uses restadmin() instead, like this even if the current user does not have the right permissions, the personal data will be fetched, that also means you should be careful using restadmin() as it can expose information that you might not want to, so limit your query fields etc., that might look something like this:
<#assign query = "SELECT login, email FROM users ORDER BY registration_data.registration_time DESC"?url /> <#assign response = restadmin("2.0", "/search?q=" + query) /> <#if response.data.items?has_content> <ol class="userlist"> <#list response.data.items as user> <li class="user"> <span class="user__login">${user.login}</span> <span class="user__email">${user.email}</span> </li> </#list> </ol> </#if>
this is untested code, so use at your own risk =)