SugarCRM Rest API set_relationship 在联系人和文档之间

SugarCRM Rest API set_relationship between Contacts and Documents

我正在尝试 (link/set_relationship) 在文档和 SugarCRM 上的联系人之间。我不确定如何专门为此构造 "name_value_list" 。至少我认为这是错误的。

我试过以下方法:

1.

'name_value_list': []

2.

'name_value_list' : [{
            'name': "documents_contacts",
            'value': 'Other',
                    }],

3.

'name_value_list': [{'table': "%s_%s" % (ModuleName, LinkedModuleName)},
                                {'fields': [
                                        {"id": str(uuid.uuid1())},
                                        {"date_modified": str(datetime.datetime.now())},
                                        {"deleted":  '0'},
                                        {"document_id": RecordID},
                                        {"contact_id": LinkedRecordID},
                                            ]

4.

'name_value_list':[{"%s_%s" % (ModuleName, LinkedModuleName): 'Other',
                                "id": str(uuid.uuid1()),
                                "date_modified": str(datetime.datetime.now()),
                                "deleted":  '0',
                                "document_id": RecordID,
                                "contact_id": LinkedRecordID
                                }]

SugarCRM CE 版本 6.5.20(内部版本 1001)

SugarCRM v4_1 休息 API 文档:

* Set a single relationship between two beans.  The items are related by module name and id.
 *
 * @param String $session -- Session ID returned by a previous call to login.
 * @param String $module_name -- name of the module that the primary record is from.  This name should be the name the module was developed under (changing a tab name is studio does not affect the name that should be passed into this method)..
 * @param String $module_id - The ID of the bean in the specified module_name
 * @param String link_field_name -- name of the link field which relates to the other module for which the relationship needs to be generated.
 * @param array related_ids -- array of related record ids for which relationships needs to be generated
 * @param array $name_value_list -- The keys of the array are the SugarBean attributes, the values of the array are the values the attributes should have.
 * @param integer $delete -- Optional, if the value 0 or nothing is passed then it will add the relationship for related_ids and if 1 is passed, it will delete this relationship for related_ids
 * @return Array - created - integer - How many relationships has been created
 *               - failed - integer - How many relationsip creation failed
 *               - deleted - integer - How many relationships were deleted
 * @exception 'SoapFault' -- The SOAP error, if any
 */
    Method [  public method set_relationship ] {
      - Parameters [7] {
        Parameter #0 [  $session ]
        Parameter #1 [  $module_name ]
        Parameter #2 [  $module_id ]
        Parameter #3 [  $link_field_name ]
        Parameter #4 [  $related_ids ]
        Parameter #5 [  $name_value_list ]
        Parameter #6 [  $delete ]
      }
    }

Python 3.7


def SetRelationship(self, ModuleName, ModuleID, LinkFieldName, RelatedID):
    method = 'set_relationship'
    data = {
        'session':self.SessionID,
        'module_name':ModuleName,
        'module_id':ModuleID,
        'link_field_name':LinkFieldName,
        'related_ids':[RelatedID, ]
            }
    response = json.loads(self.request(method, data))

SetRelationship('Documents', 'e9d22076-02fe-d95d-1abb-5d572e65dd46', 'Contacts', '2cdc28d8-763e-6232-2788-57f4e19a9ea0')

结果: {'created': 0, 'failed': 1, 'deleted': 0}

预期结果: {'created': 1, 'failed': 0, 'deleted': 0}

您可能打算打电话给

SetRelationship('Documents', 'e9d22076-02fe-d95d-1abb-5d572e65dd46', 'contacts', '2cdc28d8-763e-6232-2788-57f4e19a9ea0')

注意这里的小写 contacts,因为 API 需要文档中 link 字段的名称 不是模块的名称。

如果仍然不能解决问题,请检查 sugarcrm.log 和 php 日志中的错误。