Error authenticating in SugarCRM using APIREST in php

0

Good morning, my query is because I am doing an authentication to a CRM (SugarCRM) through its REST API which should return a JSON with my account data and a Token to make subsequent calls to the service. the problem is that when I run the php file on the server that extracts the information, it returns this array:

Array
(
   [0] =>
)

and when I run the service on my local host it returns the token and the other data without any problem, in my opinion with these tests the code is fine but it needs some configuration on the server or permissions but I do not know what could be . I would greatly appreciate your help and I thank you in advance for your interest!

I attached the connection code even so that you can confirm that "it should work fine" both locally and on the remote server:

/*          CONFIGURACION DE CONEXION API SUGARCRM              */
/*                datos de autentificacion no reales            */
$GLOBALS['serverLink_SUGARCRM']     = "/$sugarCrm$/service/v4_1/rest.php";
$GLOBALS['user_SUGARCRM']           = "usuario";
$GLOBALS['pass_SUGARCRM']           = "Contraseña";
$GLOBALS['module_SUGARCRM']         = "Contactos";
$GLOBALS['fields_SUGARCRM']         = array('id','salutation','first_name','last_name','phone_mobile','phone_home');

    function auth_sugar(){

    header('content-type: application/json');
    /*
        se establecen los datos de autentificacion en un array
        posteriormente se codifican en formato JSON
        y por ultimo se crea un array con todos los datos que se postearan
    */
    $login_parameters = array("user_auth" => array("user_name" => $GLOBALS['user_SUGARCRM'], "password" => md5($GLOBALS['pass_SUGARCRM']), "version" => "1"), "application_name" => "RestTest", "name_value_list" => array());
    $login_parametersJSON = json_encode($login_parameters);
    $post = array("method" => "login", "input_type" => "JSON", "response_type" => "JSON", "rest_data" => $login_parametersJSON);
    /*
        se crea un objeto curl con la url del API sugarCRM
    */
    $curl_request = curl_init($GLOBALS['serverLink_SUGARCRM']);

    /*
        se establecen los parametros del objeto curl
    */
    curl_setopt($curl_request, CURLOPT_POST, 1);
    curl_setopt($curl_request, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($curl_request, CURLOPT_HEADER, 1);
    curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_request, CURLOPT_FOLLOWLOCATION, 0);

    /*
        se envian los datos a la API sugarCRM
    */
    curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);

    /*
        se almacena el resultado del objeto curl en una variable y se cierra el objeto
    */
    $resultado = curl_exec($curl_request);
    curl_close($curl_request);

    /*
        se separa el objeto por retornos de carro y enter
    */
    $resultado = explode("\r\n\r\n", $resultado, 2);

    /*
        se decodifica el resultado en el array 1 de la respuesta
    */
    $response = json_decode($resultado[1],true);

    return $response['id'];
    unset($login_parameters,$login_parametersJSON,$post,$curl_request,$resultado,$response);
}
    
asked by Jesus Solis 23.09.2017 в 19:28
source

0 answers