2010-12-21 70 views
2

我想要測試SugarCRM REST API,運行最新版本的CE(6.0.1)。看來,每當我做一個查詢,API返回「null」,沒有別的。如果我省略參數,那麼API將返回API描述(文檔說明它應該)。我試圖執行一個登錄,作爲參數傳遞方法(登錄),input_type和response_type(json)和rest_data(JSON編碼的參數)。下面的代碼將查詢:SugarmCRM REST API總是返回「null」

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

我試過的參數和使用的用戶名,而不是USER_NAME不同的變化,並且都提供相同的結果,只是一個響應「空」,就是這樣。

+0

btw,Sugar CE 6.1.0可以在這裏找到:http://www.sugarcrm.com/crm/download/sugar-suite.html – StasM 2010-12-22 18:59:37

回答

0

嘗試設置input_typeresponse_typeJSON(首都)。如果它不起作用,請轉到Sugar安裝,編輯config.php條目logger =>level並將其設置爲debug而不是fatal,看看它是否提及任何錯誤。

+0

哇,使用JSON而不是json工作,耶!你剛剛救了我一天,非常感謝! – TuomasR 2010-12-21 08:32:02