如何使用API将SugarCRM中的联系人添加到TargetList/ProspectList


How to add a Contact in SugarCRM to a TargetList/ProspectList using API?

我有一个PHP脚本,它使用RestAPI在SugarCRM上自动运行一些东西。

我使用这个PHP类来管理RestAPI:
http://github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class/

现在,我想将特定联系人链接到ProspectList(目标列表)。我想这一定是通过set_relationship调用实现的,但我使用的PHPClass没有。

我试着自己这样写函数:

public function set_relationship($module_ids, $module_names, $related_ids, $link_field_names){
    $call_arguments = array(
        'session' => $this->session,
        'module_names' => $module_names,
        'module_ids' => $module_ids,
        'link_field_names' => $link_field_names,
        'related_ids' => array($related_ids)
    );
    $result = $this->rest_request(
        'set_relationship',
        $call_arguments
    );
    return $result;
}

然后这样称呼它:

$c->set_relationship(
    $target_list['id'],
    'ProspectLists',
    $data['id'],
    'Contacts'
);

但它不起作用。有人知道如何进行REST/Soap调用来将联系人连接到目标列表吗?

感谢

根据您的信息,我可以想到两个问题。

  1. 模块可能不是公共的,这是REST/SOAP API所必需的
  2. 根据文件,这些论点的名称似乎是错误的

具有更新参数的方法:

public function set_relationship($module_name, $module_id, $link_field_name, $related_ids){
    $call_arguments = array(
        'session' => $this->session,
        'module_name' => $module_name,
        'module_id' => $module_id,
        'link_field_name' => $link_field_name,
        'related_ids' => array($related_ids)
    );
    $result = $this->rest_request(
        'set_relationship',
        $call_arguments
    );
    return $result;
}

呼叫是

$c->set_relationship(
    'ProspectLists', 
    $target_list['id'],
    'contacts',
    $data['id']    
);

所以我终于弄明白了,我使用了Kare答案中的函数:

public function set_relationship($module_name, $module_id, $link_field_name, $related_ids){
    $call_arguments = array(
        'session' => $this->session,
        'module_name' => $module_name,
        'module_id' => $module_id,
        'link_field_name' => $link_field_name,
        'related_ids' => array($related_ids)
    );
    $result = $this->rest_request(
        'set_relationship',
        $call_arguments
    );
    return $result;
}

但我不得不做出不同的决定:

$c->set_relationship(
    'Contacts',
    $contact_id,
    'prospect_lists',
    $target_list_id
);

我希望这将帮助