3

我正在尝试使用 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"}'

我希望获得与此帐户相关的所有联系人,但我收到错误“... MySQL 错误 1054:'where 子句'中的未知列'contacts.account_id'”

但是,当我尝试获取所有联系人而不提供任何查询 (query='') 时,我会获取所有联系人及其所有属性,并且可以看到有一个 account_id 属性。

任何人都可以帮忙吗?

4

3 回答 3

4

试试query:"accounts.id=some-valid-id"

过去它对我有用SOAP API

于 2012-09-27T12:55:27.887 回答
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...
        )
)

供参考

这是“rest-data”(格式很好)

使用了 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={"session":"iov5a257lk5acsg9l3ll6kuej3","module_name":"Accounts","query":"accounts.id='e583715b-7168-5d61-5fb1-513510b39705'","order_by" :null,"offset":0,"select_fields":["id","name"],"link_name_to_fields_array":[{"name":"contacts","value":["id","email1", "name","title","phone_work","description"]}],"max_results":20,"deleted":"FALSE"}method=logout&input_type=JSON&response_type=JSON&rest_data={"session":"iov5a257lk5acsg9l3ll6kuej3"}

于 2013-06-26T07:49:55.660 回答
1

我还不熟悉 SugarCRM,但是您是否尝试过仅使用 account_id=some-valid-id ?因为我也做了一个 REST 请求来添加一个联系人到 sugarcrm 并且我没有提到表的名称,只是字段。我没有尝试过,但对我来说这似乎是合乎逻辑的,因为您已经提到了模块的名称,所以我猜糖知道在处理您的查询时要查找什么表。

于 2012-09-27T08:07:40.223 回答