Client side error calling api 401 (Unauthorized) (v2021)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
onoboa
User
Posts: 86
Location: Guayaquil - Ecuador

Client side error calling api 401 (Unauthorized) (v2021)

Post by onoboa »

I have a problem with a form that has autofill, when I select the record that contains the information, the data is not loaded in the related fields of the form, apparently it is because there is an error in the client side event when a function cannot be executed of the api that updates the patient's age, I am using the administrator user so I don't understand why it says that access to the function is not authorized.

PHPmaker 2021

The Startup Script calling api

	$.ajax({
                url: 'api/edadPaciente/' + $paciente,
                type: 'GET',
                contentType:'json',
                dataType: 'json',   
                async:false,
                success: function (data) {
                		
                		console.log(data);
                		typeof(data);
                		$edad = data;
                		
                		console.log($edad);
                    	$('#x_edad').val($edad);                   
                    },
                error: function (xhr, textStatus, errorThrown) {
                     	console.log('a' + textStatus);
                     	}
               });	

The function is in Global-> Api_Action

//Consulta edad del paciente
        $app->get('/edadPaciente/{paciente}', function ($request, $response, $args) {
    		// Get input values
    		$paciente = $args["paciente"];
    		if ($paciente !== null) {
        		
        		$mSql = "";
        		$mSql = "SELECT fnc_paciente_edad('" .  AdjustSql($paciente) . "') AS edad; " ;
       		
        		$response = $response->withJson(ExecuteScalar($mSql)); // Output field value as string
        		
        	}
        	return $response; // Return Psr\Http\Message\ResponseInterface object  
        });

This is the error in client side
jquery-3.6.0.min.js:2


    
   GET http://localhost:8089/hrmedic/api/edadPaciente/ 401 (Unauthorized)

onoboa
User
Posts: 86
Location: Guayaquil - Ecuador

Post by onoboa »

This is another error

:8089/hrmedic/api/lookup:1


    
   Failed to load resource: the server responded with a status of 401 (Unauthorized)

mobhar
User
Posts: 11727

Post by mobhar »

Make sure you have already logged in and you have already given the lookup permission for that table.


Post Reply