-->

SugarCRM的:如何获得通过REST API一个帐户的所有联系人(SugarCRM: how t

2019-09-23 02:41发布

我试图让使用V2 REST API特定帐户(我知道帐户ID)从SugarCRM的所有联系人。

我送下列参数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’”

但是,当我试图让所有的联系人无需提供任何查询(查询=“”)我得到的所有与他们的所有属性的接触,我可以看到,有一个ACCOUNT_ID财产。

任何人都可以帮忙吗?

Answer 1:

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

它与过去曾为我SOAP API



Answer 2:

这里是我的方法。 它使用该包装类: 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”}



Answer 3:

我不熟悉的SugarCRM还,但你尝试只用ACCOUNT_ID =一些化有效ID? 因为我也做了一个REST请求添加联系人到SugarCRM的,我没有提到表的名字,只是领域。 我没有尝试这一点,但它似乎合乎逻辑的我,因为你已经mentionned模块的名字,所以我猜糖那种知道什么表(S?)看处理您的查询时。



文章来源: SugarCRM: how to get all contacts for an account via REST API
标签: sugarcrm