user2670222
user2670222

Reputation: 43

Getting "Access Denied" while using query in SugarCRM SOAP API in C#

I am using SOAP API client for SugarCRM in C#. I have added Web Reference of SugarCRM in my windows application. I need to get list of Leads created before particular TimeStamp. For this I am doing as follows:

try
            {
                //Fields to retrieve
                string[] Lead_fields = new string[] { "id", "name", "phone_home", "phone_mobile", "phone_work", "phone_other", "phone_fax", "deleted" ,"gclid_c"};

                LastSyncDateTime = ReadLastSyncDateTime();
                DateTime dtTemp = TimeZone.CurrentTimeZone.ToUniversalTime(Convert.ToDateTime(LastSyncDateTime));
                string sDate = String.Format("{0:yyyy-MM-dd HH:mm:ss}", dtTemp);
                string L_date_created = sDate; //LastSyncDateTime;
                string Leads_query = "(Leads.date_modified  <= " + L_date_created + ") AND Leads.deleted = 0";

                //As on 2014.11.07 (getting exception : Access Denied)
                SugarCRM.get_entry_list_result_version2 Leads_result = SugarClient.get_entry_list(SessionId, "Leads", Leads_query, "", 0, Lead_fields, null, 30, 0, true);
                if (Leads_result.entry_list.Count() > 0)
                {
                    for (int i = 0; i < Leads_result.entry_list.Count(); i++)
                    {
                        MyLeads newLead = new MyLeads();
                        newLead.LeadId = Leads_result.entry_list[i].name_value_list[0].value;
                        MyLeadsList.Add(newLead);      
                    }
                }

            }
            catch (Exception ex) 
            {
                LogMessageToFile("ERROR : " + ex.Message.ToString());
            }

Please note that I am able to login successfully as an Admin in this. Please help with this.

Upvotes: 2

Views: 738

Answers (1)

user2670222
user2670222

Reputation: 43

I got it working. There aren't any docs available for this to lead you in right direction but I just made a guess and it's worked. I just quoted the L_date_created field. So the query will look like as follows :

string Leads_query = "(Leads.date_entered  <= '" + L_date_created + "') AND Leads.deleted = 0";

And whoaaa! It's working..

Upvotes: 2

Related Questions