How to get over error 40 “Access Denied — You do n

2019-07-15 23:59发布

问题:

Here are the request params (url = http://sugarcrm.localhost/service/v4_1/rest.php):

method=get_entry_list&input_type=json&response_type=json
&rest_data {"session":"2q67jvlce802e4htsqc94oshkat9henvicvfclprhrbd8ef6k0o0",
"module_name":"Contacts",
"query":"email1=ychaouche@feeder.fr",
"order_by":"",
"offset":0,
"select_fields":[],
"link_name_to_fields_array":[],
"max_results":0,
"deleted":false}

I get this as a result :

"{"name":"Access Denied","number":40,"description":"You do not have access"}"

Edit

This error is fired whenever the subquery is malformed, not necessarily when one doesn't have access to a module, so one should be aware of it.

回答1:

Well, one solution to my problem is to replace that query with this one :

contacts.id 
IN 
(
   SELECT email_addr_bean_rel.bean_id
   FROM   email_addr_bean_rel
   JOIN   email_addresses
   ON     email_addr_bean_rel.email_address_id = email_addresses.id
   WHERE
   email_addresses.email_address = 'ychaouche@feeder.fr'
)   

Since appearantly the email1 and email2 fields are not queriable (they're not in the Contacts table). The workaround consists of querying the email_address table via a subquery.

EDIT : so that the whole query should look something like this :

method=get_entry_list&input_type=json&response_type=json
&rest_data {"session":"2q67jvlce802e4htsqc94oshkat9henvicvfclprhrbd8ef6k0o0",
"module_name":"Contacts",
"query":
"
contacts.id 
IN 
(
   SELECT email_addr_bean_rel.bean_id
   FROM   email_addr_bean_rel
   JOIN   email_addresses
   ON     email_addr_bean_rel.email_address_id = email_addresses.id
   WHERE
   email_addresses.email_address = 'ychaouche@feeder.fr'
)  
"
"order_by":"",
"offset":0,
"select_fields":[],
"link_name_to_fields_array":[],
"max_results":0,
"deleted":false}