我正在尝试通过REST服务调用向Sugar中的目标列表添加目标。我得到了Sugar的积极回应,但没有添加记录。我正在使用的服务方法是* set_relationship *:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"ProspectLists",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospects",
"name_value_list":[],
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
我也反过来试过了:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"Prospects",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospect_lists",
"name_value_list":[],
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
在这两种情况下,我都有一个很有希望的回复:
{"created":1,"failed":0,"deleted":0}
...但是当我检查目标列表时,我找不到任何添加的目标。我也检查了数据库,但也没有任何痕迹。
My Sugar Version 6.5.16 CE ,我正在使用SuiteCRM 7.0.1扩展程序,但我不认为这会有所不同。
任何提示都非常受欢迎。谢谢!
答案 0 :(得分:3)
我终于明白了。似乎set_relationship对参数顺序非常挑剔。参数命名甚至不意味着什么。这对我来说最终有效:
{
"session":"3ece4lmn5rtweq9vm5581jht",
"module_name":"Prospects",
"module_id":"cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name":"prospect_lists",
"related_ids":["534f894a-4265-143d-c94b-52be908685b1"],
"delete":0
}
答案 1 :(得分:0)
使用Python代码(API v4.1):
import sugarcrm
import json
import requests
crm_session = sugarcrm.Session(CRM_HOST, CRM_USER, CRM_PASS)
payload = {
"method": "set_relationship",
"input_type": "JSON",
"response_type": "JSON",
"rest_data": json.dumps({
"session": crm_session.session_id,
"module_name": "Prospects",
# ID of the record you're creating relationship FROM
# In my case it is a record from module "Prospects"
"module_id": "cb13b96f-8334-733c-1548-52c27a5b8b99",
"link_field_name": "events_prospects",
# ID of the record you're creating relationship FOR
# In my case it is a record from module "events"
"related_ids": ["534f894a-4265-143d-c94b-52be908685b1"],
"name_value_list": [],
"delete": 0
})
}
result = requests.post(CRM_HOST, data=payload)
@Till是对的,请注意“rest_data”参数的顺序。在我的情况下,在name_value_list
之前放置related_ids
已经产生了积极的结果而没有创建实际的关系。
P.S。我正在使用这个库:https://pypi.python.org/pypi/sugarcrm/0.1