我想根据sugarcrm rest api using C# .net
我试过了
json = serializer.Serialize(new
{
session = sessionId,
module_name = "accounts",
query = "",
order_by = "",
offset = "0",
select_fields = "",
link_name_to_fields_array = "",
max_results = "2000",
deleted = 0
});
values = new NameValueCollection();
values["method"] = "get_entry_list";
values["input_type"] = "json";
values["response_type"] = "json";
values["rest_data"] = json;
response = client.UploadValues(sugarUrl, values);
responseString = Encoding.Default.GetString(response);
var accountsList = serializer.Deserialize<Dictionary<string, dynamic>>(responseString);
我能够获得所有帐户和联系人,但我没有得到他们之间的关系,即哪个联系人属于哪个帐户
提前感谢您的帮助
更新:
object[] linkNameToFieldsArray = new object[1]
{
new object[2, 2]
{
{ "name", "contacts" },
{ "value", new string[2]
{ "id", "last_name"
}
}
};
json = serializer.Serialize(new
{
session = sessionId,
module_name = "accounts",
query = "",
order_by = "",
offset = "0",
select_fields = "",
link_name_to_fields_array = linkNameToFieldsArray , ***//just added this to get related records***
max_results = "2000",
deleted = 0
});
values = new NameValueCollection();
values["method"] = "get_entry_list";
values["input_type"] = "json";
values["response_type"] = "json";
values["rest_data"] = json;
response = client.UploadValues(sugarUrl, values);
responseString = Encoding.Default.GetString(response);
var accountsList = serializer.Deserialize<Dictionary<string, dynamic>>(responseString);
答案 0 :(得分:1)
假设SugarCRM 6.4或6.5系统和API版本REST v4_1 ...
我不知道C#/。NET语法/术语,但是&#39; link_name_to_fields_array&#39;需要是一个包含模块名称键的数组(例如&#34; Contacts&#34;)和值是您想要的字段数组。 JSON看起来像这样:
{
"session":"asdfasdfsrf9ebp7jrr71nrth5",
"module_name":"Accounts",
"query":"",
"order_by":null,
"offset":0,
"select_fields":[
"id",
"name"
],
"link_name_to_fields_array":[
{
"name":"contacts",
"value":[
"id",
"last_name"
]
}
],
"max_results":"2",
"deleted":false
}
另外 - 我写这篇文章是为了帮助非PHP-devs与这个版本的API进行交互,因为文档基本上是基于PHP的。您可能会发现它很有用:https://gist.github.com/matthewpoer/b9366ca4197a521a600f