SugarmCRM REST API始终返回“null”

时间:2010-12-21 06:51:57

标签: php rest sugarcrm

我正在尝试测试SugarCRM REST API,运行最新版本的CE(6.0.1)。似乎每当我进行查询时,API都返回“null”,没有别的。如果我省略了参数,那么API将返回API描述(文档说明应该这样做)。

我正在尝试执行登录,将方法(login),input_type和response_type(json)以及rest_data(JSON编码参数)作为参数传递。以下代码执行查询:

 $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";

我尝试了不同的参数变体并使用username而不是user_name,并且都提供了相同的结果,只是响应“null”,就是这样。

1 个答案:

答案 0 :(得分:0)

尝试将input_typeresponse_type设置为JSON(大写字母)。如果它不起作用,请转到Sugar安装,编辑config.php =>下的logger条目。 level并将其设为debug而不是fatal,看看是否有任何错误。

相关问题