401 error in a custom api

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Cat
User
Posts: 98

401 error in a custom api

Post by Cat »

hello everyone

I have a 401 error in a custom api

I have the code in Api_Action

$app->get('/getChatByName/{nombre}', function ($request, $response, $args) {
        $name = $args["nombre"] ?? null; // Get the input value
        if ($name !== null) {
        
          //  $response = $response->write(ExecuteScalar("SELECT chat_id FROM usuarios WHERE nombre = '" . AdjustSql($name) . "'")); // 
            $response = $response->write(ExecuteScalar("SELECT chat_id FROM usuarios WHERE nombre = " . AdjustSql($name))); // Output field value as string
        }
        return $response; // Return Psr\Http\Message\ResponseInterface object
    });

}

and in the table specify client_scrips

$("#x_DESTINATARIO").change(function() {
    $.get(ew.getApiUrl(["getChatByName", $(this).val()]), function(res) {
        if (res)
            $("#x_ChatID").val(res);  // Set the result (manipulate it first if necessary) to the target field
    });
});

I am logging in as administrator

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

the users table is not the security table

phpmaker 2024.13


arbei
User
Posts: 9862

Post by arbei »

Make sure $(this).val() has value or the URL does not meet '/getChatByName/{nombre}'.


DGarza
User
Posts: 159

Post by DGarza »

Cat wrote:

$("#x_DESTINATARIO").change(function() {
    $.get(ew.getApiUrl(["getChatByName", $(this).val()]), function(res) {
        if (res)
            $("#x_ChatID").val(res);  // Set the result (manipulate it
first if necessary) to the target field
    });
});

Befere the condition add console.log(res) for see what it get and see the value


Post Reply