最新バージョンのCE(6.0.1)を実行しているSugarCRMRESTAPIをテストしようとしています。クエリを実行するたびに、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";
さまざまなバリエーションのパラメーターを試し、user_nameの代わりにusernameを使用しましたが、すべて同じ結果が得られ、応答は「null」でした。