# Response app function

**URL:** <https://community.dynatrace.com/t/response-app-function/45344>\
**Category:** Developer Q&A Forum\
**Created:** [April 29, 2024, 3:08pm UTC](https://community.dynatrace.com/t/response-app-function/45344 "2024-04-29T15:08:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![meblanc](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@meblanc](https://community.dynatrace.com/u/meblanc)\
**Post date:** [April 29, 2024, 3:08pm UTC](https://community.dynatrace.com/t/response-app-function/45344/1 "2024-04-29T15:08:35Z")

</div>

Hello everyone, I wanted to ask you the following: I have a function(consultar.ts) that queries the user management API and retrieves a list of the users created in the platform. This is invoked from a page (conusuario.tsx). I wanted to know how I can display that information on that page in a table. As you know, the response is in JSON format.

[//consultar.tsexport](https://consultar.tsexport) default async function consultarUsuario(): Promise\<void\> {&nbsp; const obtenerToken = async (): Promise\<string\> =\> {&nbsp; &nbsp; const data = new URLSearchParams();&nbsp; &nbsp; data.append(‘grant\_type’, ‘client\_credentials’);&nbsp; &nbsp; data.append(‘client\_id’, ‘client.id’);&nbsp; &nbsp; data.append(‘client\_secret’, ‘secret’);&nbsp; &nbsp; data.append(‘scope’, ‘scope’);  
&nbsp; &nbsp; const options = {&nbsp; &nbsp; &nbsp; method: ‘POST’,&nbsp; &nbsp; &nbsp; headers: {&nbsp; &nbsp; &nbsp; &nbsp; ‘Content-Type’: ‘application/x-www-form-urlencoded’,&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; body: data.toString(),&nbsp; &nbsp; };  
&nbsp; &nbsp; const response = await fetch(‘[https://sso.dynatrace.com/sso/oauth2/token](https://sso.dynatrace.com/sso/oauth2/token)’, options);  
&nbsp; &nbsp; if (!response.ok) {&nbsp; &nbsp; &nbsp; throw new Error(`Error en la solicitud: ${response.status} ${response.statusText}`);&nbsp; &nbsp; }  
&nbsp; &nbsp; const parsedData = await response.json();&nbsp; &nbsp; return parsedData.access\_token;&nbsp; };  
&nbsp; const consultarUsuarioDeDynatrace = async (token: string): Promise\<void\> =\> {&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;const url = `[https://api.dynatrace.com/iam/v1/accounts/account/users\`](https://api.dynatrace.com/iam/v1/accounts/account/users%5C%60);  
&nbsp; &nbsp; &nbsp; const options = {&nbsp; &nbsp; &nbsp; &nbsp; method: ‘GET’,&nbsp; &nbsp; &nbsp; &nbsp; headers: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘Authorization’: `Bearer ${token}`,&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; };  
&nbsp; &nbsp; &nbsp; const response = await fetch(url, options);  
&nbsp; &nbsp; &nbsp; if (!response.ok) {&nbsp; &nbsp; &nbsp; &nbsp; throw new Error(`Error en la solicitud: ${response.status} ${response.statusText}`);&nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; const data = await response.json();  
&nbsp; &nbsp; &nbsp; const usuariosFiltrados = data.items.filter((usuario: any) =\> !usuario.email.toLowerCase().includes('@xxxxx.com’));  
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;console.log(‘Listado de usuarios filtrados2:’);&nbsp; &nbsp; &nbsp; console.log(usuariosFiltrados);&nbsp; &nbsp; } catch (error) {&nbsp; &nbsp; &nbsp; console.error(‘Error al consultar usuarios:’, error);&nbsp; &nbsp; &nbsp; throw error;&nbsp; &nbsp; }&nbsp; };  
&nbsp; try {&nbsp; &nbsp; const token = await obtenerToken();&nbsp; &nbsp; await consultarUsuarioDeDynatrace(token);&nbsp; } catch (error) {&nbsp; &nbsp; console.error(‘Error:’, error);&nbsp; &nbsp; throw error;&nbsp; }}

Page:

// consusuario.tsximport React, { useState } from “react”;import { Flex, Heading, useCurrentTheme } from “@dynatrace/strato-components-preview”;import { Button } from ‘@dynatrace/strato-components-preview/buttons’;import { functions } from “@dynatrace-sdk/app-utils”;  
const ConUsuario = () =\> {&nbsp; const handleConUsuario = async () =\> {&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; functions.call(‘consultar’, {});&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;} catch (error) {&nbsp; &nbsp; &nbsp; console.error(‘Error al consultar usuarios:’, error);&nbsp; &nbsp; }&nbsp; };  
&nbsp; const theme = useCurrentTheme();  
&nbsp; return (&nbsp; &nbsp; \<Flex flexDirection=“column” alignItems=“center” padding={32}\>&nbsp; &nbsp; &nbsp; \<img&nbsp; &nbsp; &nbsp; &nbsp; src=“./assets/xxxxx.png”&nbsp; &nbsp; &nbsp; &nbsp; alt=“Xxxxxxxx”&nbsp; &nbsp; &nbsp; &nbsp; width={100}&nbsp; &nbsp; &nbsp; &nbsp; height={100}&nbsp; &nbsp; &nbsp; &nbsp; style={{ paddingBottom: 16 }}&nbsp; &nbsp; &nbsp; /\>&nbsp; &nbsp; &nbsp; \<Heading\>Consultar Usuarios\</Heading\>  
&nbsp; &nbsp; &nbsp; \<Flex gap={56} paddingTop={64} flexFlow=“wrap”\>&nbsp; &nbsp; &nbsp; &nbsp; \<div\>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<Flex flexDirection=“column” alignItems=“center” gap={16}\>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<img&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src={theme === “light” ? “./assets/consultar.png” : “./assets/consultar.png”}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alt=“Consultar usuarios”&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height=“100px”&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width=“100px”&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /\>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<Button onClick={handleConUsuario}\>Consultar usuarios\</Button\>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \</Flex\>&nbsp; &nbsp; &nbsp; &nbsp; \</div\>&nbsp; &nbsp; &nbsp; \</Flex\>&nbsp; &nbsp; \</Flex\>&nbsp; );};  
export default ConUsuario;

---

<div class="post-metadata">

**Author:** ![SarahFaustmann](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@SarahFaustmann](https://community.dynatrace.com/u/SarahFaustmann)\
**Post date:** [April 29, 2024, 4:36pm UTC](https://community.dynatrace.com/t/response-app-function/45344/2 "2024-04-29T16:36:44Z")

</div>

Hi&nbsp;[@meblanc](https://community.dynatrace.com/user/73869),

I’m not sure I understand correctly, but in general, you’ll have to parse the json and can then use the [DataTable](https://developer.dynatrace.com/reference/design-system/preview/tables/DataTable/) or [SimpleTable](https://developer.dynatrace.com/reference/design-system/preview/tables/SimpleTable/) component to display your data in a table. You can find code examples on the component pages, as well as CodeSandbox links.

Kind regards,  
Sarah

---

<div class="post-metadata">

**Author:** ![SarahFaustmann](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@SarahFaustmann](https://community.dynatrace.com/u/SarahFaustmann)\
**Post date:** [May 15, 2024, 11:17am UTC](https://community.dynatrace.com/t/response-app-function/45344/3 "2024-05-15T11:17:23Z")

</div>

Hi&nbsp;[@meblanc](https://community.dynatrace.com/user/73869),

Have you solved you issue? If you reply helped, would you mind marking it as solved?

Kind regards,  
Sarah
