我正在尝试使用v2 REST API从SugarCRM获取特定帐户的所有联系人(我知道帐户ID)。
我发送的GET请求包含以下参数:
input_type => 'JSON'
response_type => 'JSON'
method => 'get_entry_list'
rest_data => '{session:"some-valid-session-id", module_name:"Contacts", query:"contacts.account_id=some-valid-id"}'
我希望获得与此accoutn相关的所有联系人,但我得到一个错误“...... MySQL错误1054:'where子句'中的未知列'contacts.account_id'”
然而,当我尝试在不提供任何查询的情况下获取所有联系人(query ='')时,我获得了所有属性的所有联系人,我可以看到有一个account_id属性。
有人可以帮忙吗?
答案 0 :(得分:4)
试试query:"accounts.id=some-valid-id"
。
过去使用SOAP API
。
答案 1 :(得分:4)
这是我的方法。它使用此包装类:http://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class/
/**
* returns an array of contacts that are related to the accountId passed as a param.
* The array returned will be an array of associative arrays.
* @param $accountId
* @param array $contactSelectFields optional sets the different items to return, default includes id, email1, name, title, phone_work, and description
* @return array
*
*/
public function getAllContactsAtOrganization( $accountId, $contactSelectFields=array("id", "email1", "name", "title", "phone_work", "description")) {
$sugar = new Sugar_REST( SUGAR_REST_URL, SUGAR_USER_NAME, SUGAR_PASSWORD);
$fields = array( "Accounts" => array("id", "name"),
"Contacts" => $contactSelectFields);
$options = array(
'where' => "accounts.id='$accountId'"
);
$apiResult = $sugar->get_with_related("Accounts", $fields, $options );
$contacts = array();
foreach( $apiResult['relationship_list'][0]['link_list'][0]['records'] as $almostContact) {
$curr = array();
foreach($contactSelectFields as $key) {
$curr[$key] = $almostContact['link_value'][$key]['value'];
}
$contacts[] = $curr;
}
//print_r($contacts);
return $contacts;
}
Array
(
[0] => Array
(
[id] => 47e1376c-3029-fc42-5ae2-51aeead1041b
[email1] => johndoe@gmail.com
[name] => Blake Robertson
[title] => CTO
[phone_work] => 8881112222
[description] => Opinionated developer that hates SugarCRM's REST API with a passion!
)
[1] => Array
(
[id] => 4c8e3fcf-8e69-ed7d-e239-51a8efa4f530
[email1] => csmith@mailinator.com
[name] => Carolyn Smith
[title] => Director of Something
[phone_work] => 832-211-2222
[description] => She's a smooth operator...
)
)
使用php数组的print_r
Array
(
[session] => 9j7fm4268l0aqm25kvf9v567t3
[module_name] => Accounts
[query] => accounts.id='e583715b-7168-5d61-5fb1-513510b39705'
[order_by] =>
[offset] => 0
[select_fields] => Array
(
[0] => id
[1] => name
)
[link_name_to_fields_array] => Array
(
[0] => Array
(
[name] => contacts
[value] => Array
(
[0] => id
[1] => email1
[2] => name
[3] => title
[4] => phone_work
[5] => description
)
)
)
[max_results] => 20
[deleted] => FALSE
)
方法= get_entry_list&安培; INPUT_TYPE = JSON&安培; RESPONSE_TYPE = JSON&安培; rest_data = { “会话”: “iov5a257lk5acsg9l3ll6kuej3”, “模块名”: “帐户”, “查询”:“accounts.id ='e583715b-7168-5d61- 5fb1-513510b39705' ”, “ORDER_BY”:NULL, “偏移量”:0, “select_fields”:[ “ID”, “名称”], “link_name_to_fields_array”:[{ “名称”: “联系人”, “值”: [ “ID”, “EMAIL1”, “姓名”, “标题”, “phone_work”, “描述”]}], “MAX_RESULTS”:20, “已删除”: “FALSE”}方法=注销&安培; INPUT_TYPE = JSON&安培; RESPONSE_TYPE = JSON&安培; rest_data = { “会话”: “iov5a257lk5acsg9l3ll6kuej3”}
答案 2 :(得分:1)
我还不熟悉SugarCRM,但你是否尝试使用account_id = some-valid-id?因为我也做了一个REST请求来向sugarcrm添加联系人,我没有提到表的名称,只是字段。我没试过这个,但这对我来说似乎合乎逻辑,因为你已经提到了模块的名字,所以我想糖有点知道在处理你的查询时要查找的表(s?)。