带php的suitecrm rest api
我正在SuiteRM中尝试我的第一步,并设法安装、添加了一些数据并进行了一些测试 因为我的目标是通过php使用RESTAPI,所以我想连接到应用程序 我找到了一些例子,但它似乎没有给我任何东西。我可以请一位专家为我提供一个良好的起点(或代码),作为通过API读取应用程序中的用户或帐户的示例吗 我尝试了以下链接: 提供正确的URL和登录凭据,但我甚至没有收到一行回复 到目前为止,我已经做了:带php的suitecrm rest api,php,rest,sugarcrm,suitecrm,Php,Rest,Sugarcrm,Suitecrm,我正在SuiteRM中尝试我的第一步,并设法安装、添加了一些数据并进行了一些测试 因为我的目标是通过php使用RESTAPI,所以我想连接到应用程序 我找到了一些例子,但它似乎没有给我任何东西。我可以请一位专家为我提供一个良好的起点(或代码),作为通过API读取应用程序中的用户或帐户的示例吗 我尝试了以下链接: 提供正确的URL和登录凭据,但我甚至没有收到一行回复 到目前为止,我已经做了: 使用API安装SuiteRM 检查了URL,它可以返回默认信息 我添加了一个打印(“你好”);每次运行
- 使用API安装SuiteRM
- 检查了URL,它可以返回默认信息
- 我添加了一个打印(“你好”);每次运行脚本时打印的行
- 选中此链接:默认登录没有运气
$url = "http://http://demo.suiteondemand.com/service/v4_1/rest.php";
$username = "will";
$password = "will";
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
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);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
//login ----------------------------------------
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => md5($password),
"version" => "1"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
$login_result = call("login", $login_parameters, $url);
/*
echo "<pre>";
print_r($login_result); //nothing
echo "</pre>";
*/
//get session id
$session_id = $login_result->id;
//retrieve fields --------------------------------
$get_module_fields_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//Optional. Returns vardefs for the specified fields. An empty array will return all fields.
'fields' => array(
'id',
'name',
),
);
$get_module_fields_result = call("get_module_fields", $get_module_fields_parameters, $url);
echo "<pre>";
print_r($get_module_fields_result); //nothing again
echo "</pre>";
啊,没想到这会是一个问题,但你犯了一个打字错误。检查rest端点的URL。您需要用适当的结构将其指向HTTPS。以下是更新的(对我来说工作正常)代码:
啊,没想到这会是一个问题,但你犯了一个打字错误。检查rest端点的URL。您需要用适当的结构将其指向HTTPS。以下是更新的(对我来说工作正常)代码:
不看你的代码就什么都说不出来。但例子肯定会有所帮助。我以前用过。嗨,非常感谢你的提示。我在演示网站上收到了一条“错误处理结果”消息,也是v2。你最近运气好吗?不看你的代码就说不出什么。但例子肯定会有所帮助。我以前用过。嗨,非常感谢你的提示。我在演示网站上收到了一条“错误处理结果”消息,也是v2。你最近运气好吗?你好!谢谢你的提示。我的网站没有HTTPS,因此无法正常工作。有办法吗?非常感谢。只需将URL从HTTPS更改为HTTP即可。希望这将为你工作。嗨,非常感谢,我已经尝试了http和IP地址,但它没有产生相同的信息。这可能是SSL或我的安装。。。我还不知道。嗨,星,我用http代码编辑了我的问题。它会忽略http url吗?SuiteRM对http或HTTPS有限制。如果仍然无法正常工作,则可能与服务器有关,而不是SuiteRM instance.hello的HTTP或HTTPs!谢谢你的提示。我的网站没有HTTPS,因此无法正常工作。有办法吗?非常感谢。只需将URL从HTTPS更改为HTTP即可。希望这将为你工作。嗨,非常感谢,我已经尝试了http和IP地址,但它没有产生相同的信息。这可能是SSL或我的安装。。。我还不知道。嗨,星,我用http代码编辑了我的问题。它会忽略http url吗?SuiteRM对http或HTTPS有限制。如果仍然无法正常工作,则可能与服务器有关,而不是SuiteRM实例的HTTP或HTTPs。
hello<pre></pre>
$url = "http://my_domain.com/suiteCRM/service/v4_1/rest.php";
$username = "user";
$password = "pass";
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
curl_setopt($curl_request, CURLOPT_POST, 1);
$url = "https://demo.suiteondemand.com/service/v4_1/rest.php";
$username = "will";
$password = "will";
function call($method, $parameters, $url)
{
ob_start();
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_URL, $url);
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);
$jsonEncodedData = json_encode($parameters);
$post = array(
"method" => $method,
"input_type" => "JSON",
"response_type" => "JSON",
"rest_data" => $jsonEncodedData
);
curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($curl_request);
curl_close($curl_request);
$result = explode("\r\n\r\n", $result, 2);
$response = json_decode($result[1]);
ob_end_flush();
return $response;
}
//login ----------------------------------------
$login_parameters = array(
"user_auth" => array(
"user_name" => $username,
"password" => md5($password),
"version" => "1"
),
"application_name" => "RestTest",
"name_value_list" => array(),
);
$login_result = call("login", $login_parameters, $url);
/*
echo "<pre>";
print_r($login_result); //nothing
echo "</pre>";
*/
//get session id
$session_id = $login_result->id;
//retrieve fields --------------------------------
$get_module_fields_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Accounts',
//Optional. Returns vardefs for the specified fields. An empty array will return all fields.
'fields' => array(
'id',
'name',
),
);
$get_module_fields_result = call("get_module_fields", $get_module_fields_parameters, $url);
echo "<pre>";
print_r($get_module_fields_result); //nothing again
echo "</pre>";
stdClass Object
(
[module_name] => Accounts
[table_name] => accounts
[module_fields] => stdClass Object
(
[id] => stdClass Object
(
[name] => id
[type] => id
[group] =>
[id_name] =>
[label] => ID
[required] => 1
[options] => Array
(
)
[related_module] =>
[calculated] =>
[len] =>
)
[name] => stdClass Object
(
[name] => name
[type] => name
[group] =>
[id_name] =>
[label] => Name:
[required] => 1
[options] => Array
(
)
[related_module] =>
[calculated] =>
[len] => 150
)
)
[link_fields] => Array
(
)
)