Retriving specific fields using /api/v2/users endpoint

Hi,

I am using a method to get the list of all the users as below,

@GetMapping(value="/users")
    @ResponseBody
    public ResponseEntity<String> users(HttpServletRequest request, HttpServletResponse response) {

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Authorization", "Bearer " + controller.getManagementApiToken());

        HttpEntity<String> entity = new HttpEntity<String>(headers);

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> result = restTemplate.exchange("https://" + domain + "/api/v2/users", HttpMethod.GET, entity, String.class);
        System.out.println(result);
        return result;

    }

Now, in the documentation, it was mentioned that we can select specific fields and only retrive those. How can I do this? I tried to set the parameters in the headers (both ‘fields’ and ‘include_fields’) but it’s not getting the expected result. I am just starting to use this. Would love to get an answer.

Thank you!

Hi @aloysius ,

Thank you for posting this topic on the Auth0 Community!

To select specific fields with the /api/v2/users endpoint, please add the fields parameter. For example,

https://{domain}/api/v2/users?fields=email,name will only retrieve email and name.

Hope this helps!

2 Likes

Hi @lihua.zhang ,

Good day to you!

I was able to implement it without any issue using the method you mentioned.

Thank you for the quick reply.

1 Like