SugarCRM REST API,如何获取与帐户相关的联系人 [英] SugarCRM REST API, how to get Contacts related to an Account

查看:27
本文介绍了SugarCRM REST API,如何获取与帐户相关的联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 SugarCRM Pro 6.5.5.我正在尝试将一些集成到另一个应用程序中,因此我需要从该其他应用程序执行一些 API 调用.我正在使用 REST API v2.此时,我需要通过帐户 ID 获取与帐户相关的联系人.我已经尝试了 get_relationships()get_entry_list(),但我无法让它们中的任何一个工作.

这是我对 get_relationships() 的输入:

{"session":"eujfbfsfjgni98m0mivl6jm6r2","module_name":"Accounts","module_id":"c03d0649-0525-2f90-1206-50881e87d7dd","link_contacts_name">

我已经尝试了很多变体,以及其他几个选项,但没有达到我想要的效果.这是上面的输出:

stdClass 对象([entry_list] =>大批([0] =>标准类对象([id] =>[模块名称] =>联系人[name_value_list] =>标准类对象([已删除] =>标准类对象([名称] =>已删除[值] =>0)[do_not_call] =>标准类对象([名称] =>不要打电话[值] =>0))))[relationship_list] =>大批())

我看不出这些信息会有什么用处.

接下来,我尝试使用 get_entry_list() 查询以仅选择具有给定帐户 ID 的联系人.这是我的意见:

{"session":"8mol33e7kdq6girugu30dnt074","module_name":"联系人","query":"accounts.id = 'c03d0649-0525-2f90-1206-50881e}dd'"/p>

我使用 accounts.id 因为我读过类似的问题,这是正确的.我尝试了很多其他的东西,例如:contacts.account_idaccount_id 等.在每种情况下,我都会在日志中收到一个 MySQL 错误,指出该列无效.

SugarCRM:如何获得通过 REST API 获取帐户的所有联系人

这个问题是相关的,似乎是完全相同的问题.我尝试在我的输入中添加一个 link_name_to_fields_array 选项,但无论我提供什么值,它都会导致日志中出现以下 MySQL 错误:

AND jt11.deleted=0 where (Array) AND contacts.deleted=0:MySQL 错误 1054:where 子句"中的未知列Array"

大夫?

谢谢.

解决方案

感谢 ychaouche,我想通了.

毕竟我能够使用 get_relationships() 方法.在将 related_fields 添加到我的输入之前,我曾尝试过,但所做的一切都导致结果集为空.答案?将 related_module_query 设置为空字符串...现在结果集不为空.是的,我昨晚 3 个多小时的疯狂谷歌就是因为那个.

所以,这里有一些工作代码,以防其他人遇到这个问题:

<代码>{"session": "iov9pg9kvvl60librung1h5fh6","module_name": "账户","module_id": "c03d0649-0525-2f90-1206-50881e87d7dd","link_field_name": "联系人","related_module_query": "",相关字段":[名",姓"],删除":假}

这让我得到了以下结果集:

stdClass 对象([entry_list] =>大批([0] =>标准类对象([id] =>[模块名称] =>联系人[name_value_list] =>标准类对象([名字] =>标准类对象([名称] =>名[值] =>约翰)[姓氏] =>标准类对象([名称] =>姓[值] =>史密斯))))[relationship_list] =>大批())

你当然可以在related_fields中指定不同的字段,获取不同的数据.

I am using SugarCRM Pro 6.5.5. I am trying to do some integration into another application, so I need to do some API calls from that other application. I am using the REST API v2. At this point, I need to get a Contact that is related to an Account via the account ID. I have tried both get_relationships() and get_entry_list(), but I can't get either of them to work.

Here's my input for get_relationships():

{"session":"eujfbfsfjgni98m0mivl6jm6r2","module_name":"Accounts","module_id":"c03d0649-0525-2f90-1206-50881e87d7dd","link_field_name":"contacts"}

I have tried many variations of this, and several other options, but nothing did what I wanted. This is the output from above:

stdClass Object
(
    [entry_list] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 
                    [module_name] => Contacts
                    [name_value_list] => stdClass Object
                        (
                            [deleted] => stdClass Object
                                (
                                    [name] => deleted
                                    [value] => 0
                                )

                            [do_not_call] => stdClass Object
                                (
                                    [name] => do_not_call
                                    [value] => 0
                                )

                        )

                )

        )

    [relationship_list] => Array
        (
        )

)

I don't see how this information could ever be useful.

Next up, I tried get_entry_list() with a query to select only the Contacts that had the given account ID. Here's my input for that:

{"session":"8mol33e7kdq6girugu30dnt074","module_name":"Contacts","query":"accounts.id = 'c03d0649-0525-2f90-1206-50881e87d7dd'"}

I am using accounts.id because I have read in similar questions, that is correct. I've tried many other things, like: contacts.account_id, account_id, etc. In every case, I get a MySQL error in the log stating the column is invalid.

SugarCRM: how to get all contacts for an account via REST API

This question is relevant, and seems to be the exact same problem. I tried adding a link_name_to_fields_array option to my input, but no matter what value I provide, it results in the following MySQL error in the log:

AND jt11.deleted=0 where (Array) AND contacts.deleted=0: MySQL error 1054: Unknown column 'Array' in 'where clause'

Dafuq?

Thanks.

解决方案

Thanks to ychaouche, I figured it out.

I was able to use the get_relationships() method after all. I had tried before adding the related_fields to my input, but all that did was result in an empty result set. The answer? Set related_module_query to an empty string... and now the result set is not empty. Yep, my 3+ hours of furious Googleing last night is because of that.

So, here is some working code in case anyone else has this problem:

{
    "session": "iov9pg9kvvl60librung1h5fh6",
    "module_name": "Accounts",
    "module_id": "c03d0649-0525-2f90-1206-50881e87d7dd",
    "link_field_name": "contacts",
    "related_module_query": "",
    "related_fields": [
        "first_name",
        "last_name"
    ],
    "deleted": false
}

This got me the following result set:

stdClass Object
(
    [entry_list] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 
                    [module_name] => Contacts
                    [name_value_list] => stdClass Object
                        (
                            [first_name] => stdClass Object
                                (
                                    [name] => first_name
                                    [value] => John
                                )

                            [last_name] => stdClass Object
                                (
                                    [name] => last_name
                                    [value] => Smith
                                )

                        )

                )

        )

    [relationship_list] => Array
        (
        )

)

You can of course specify different fields in related_fields and get different pieces of data.

这篇关于SugarCRM REST API,如何获取与帐户相关的联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆