Login - API V4_1 (Check username & Password)

Buenos días
Tengo que integrar el Login de SuiteCRM en otra aplicación. Estoy haciendo pruebas del login mediante la api V4.1, y recibo el siguiente mensaje por más que las credenciales estén correctas:

“{“name”:“Invalid Login”,“number”:10,“description”:“Login attempt failed please check the username and password”}”

La solicitud es la siguiente:


<?php

$url = 'http://<url>/test_crm/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON';
$data = array(
    'user_auth' => array(
        'user_name' => '<username>',
        'password' => md5('<password>'),
        'application_name' => '',
    ),
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

var_dump($result);

?>

También probé de la siguiente manera, que leí por acá en el foro:


<?php

$url = 'http://<url>/test_crm/service/v4_1/rest.php?method=login&input_type=JSON&response_type=JSON';
$data = array(
    'user_auth' => array(
        'user_name' => '<username>',
        'password' => '<password>',
        'application_name' => '',
        'encryption' => 'plain',
    ),
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

var_dump($result);

?>

¿Alguien sabe a que se debe este mensaje de error?

Muchas gracias.

Hey
Please look at the php example given in this documentation. It has login code as well.

There are some differences between your code and this
for example
application_name should be outside the user_auth array.

you can use the documentation code as it because it works

Hello! Thank you for responding. Well, I copied the example from the API documentation, modified my credentials and still, I receive NULL and in the SuiteCRM logs the same message: Invalid Login, please check the username and password. The credentials are ok.


<?php

$url = "http://<url>/test_crm/service/v4_1/rest.php";

function restRequest($method, $arguments){
 global $url;
 $curl = curl_init($url);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 $post = array(
         "method" => $method,
         "input_type" => "JSON",
         "response_type" => "JSON",
         "rest_data" => json_encode($arguments),
 );

 curl_setopt($curl, CURLOPT_POSTFIELDS, $post);

 $result = curl_exec($curl);
 curl_close($curl);
 return json_decode($result,1);
}


$userAuth = array(
        'user_name' => '<user>',
        'password' => md5('<password>'),
);
$appName = 'My SuiteCRM REST Client';
$nameValueList = array();

$args = array(
            'user_auth' => $userAuth,
            'application_name' => $appName,
            'name_value_list' => $nameValueList);

$result = restRequest('login',$args);
$sessId = $result['id'];

var_dump($result);

Bueno, no sé que es lo que cambió, pero ahí pude conectar siguiendo la documentación :joy: