Question

I'm trying to test out the SugarCRM REST API, running latest version of CE (6.0.1). It seems that whenever I do a query, the API returns "null", nothing else. If I omit the parameters, then the API returns the API description (which the documentation says it should).

I'm trying to perform a login, passing as parameter the method (login), input_type and response_type (json) and rest_data (JSON encoded parameters). The following code does the query:

 $api_target = "http://example.com/sugarcrm/service/v2/rest.php";

 $parameters = json_encode(array(
    "user_auth" => array(
        "user_name" => "admin",
        "password" => md5("adminpassword"),
    ),
    "application_name" => "Test",
    "name_value_list" => array(),
 ));
 $postData = http_build_query(array(
    "method" => "login",
    "input_type" => "json",
    "response_type" => "json",
    "rest_data" => $parameters
 ));
 echo $parameters . "\n";
 echo $postData . "\n";

 echo file_get_contents($api_target, false,
    stream_context_create(array(
        "http" => array(
            "method" => "POST",
            "header" => "Content-Type: application/x-www-form-urlencoded\r\n",
            "content" => $postData
        )
    ))) . "\n";

I've tried different variations of parameters and using username instead of user_name, and all provide the same result, just a response "null" and that's it.

Was it helpful?

Solution

Try setting input_type and response_type to JSON (capitals). If it doesn't work, go to Sugar installation, edit config.php entry under logger => level and make it debug instead of fatal and see if it says about any errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top