예제 #1
0
        private async void FormRequestService_RequestCreated(object sender, Web.Contract.Models.FormRequest e)
        {
            var          settingsService = DependencyResolver.Current.GetService <ISettingsService>();
            const string URL_FORMAT      = "https://{0}.bitrix24.ru/rest/{1}/{2}/{3}/";
            // {0}: userId
            // {1}: api key
            // {2}: method
            string bitrixApiKey = settingsService.GetSettings <string>("Hooks_Bitrix24_ApiKey");

            if (string.IsNullOrWhiteSpace(bitrixApiKey))
            {
                return;
            }
            int          bitrixUserId    = settingsService.GetSettings <int>("Hooks_Bitrix24_UserId");
            string       instanceName    = settingsService.GetSettings <string>("Hooks_Bitrix24_InstanceName");
            const string METHOD_LEAD_ADD = "crm.lead.add";
            var          leadAddUrl      = string.Format(URL_FORMAT, instanceName, bitrixUserId, bitrixApiKey, METHOD_LEAD_ADD);

            using (var client = new HttpClient())
            {
                var lead = new BitrixLead()
                {
                    Title        = e.Name,
                    Name         = e.Name,
                    SecondName   = "(import)",
                    LastName     = "(import)",
                    StatusId     = "NEW",
                    Opened       = "Y",
                    AssignedById = bitrixUserId,
                    CurrencyId   = "RUR",
                    Opportunity  = 0,
                    Comments     = e.Text
                };
                if (!string.IsNullOrWhiteSpace(e.Phone))
                {
                    lead.Phone = new BitrixContact[] { new BitrixContact()
                                                       {
                                                           Value     = e.Phone,
                                                           ValueType = "WORK"
                                                       } };
                }
                if (!string.IsNullOrWhiteSpace(e.Email))
                {
                    lead.Email = new BitrixContact[] { new BitrixContact()
                                                       {
                                                           Value     = e.Email,
                                                           ValueType = "WORK"
                                                       } };
                }
                var model = new BitrixApiModel()
                {
                    Fields = lead, Params = new { REGISTER_SONET_EVENT = "Y" }
                };
                var json     = JsonConvert.SerializeObject(model);
                var response = await client.PostAsync(leadAddUrl, new StringContent(json, Encoding.UTF8, "application/json"));

                var responseString = await response.Content.ReadAsStringAsync();
            }
        }
예제 #2
0
        public async Task CreateLead_Ok_Test()
        {
            var client = new Bitrix24Client(_email, _password, _b24Address);
            var lead   = new BitrixLead
            {
                Comments     = "Комментарий к лиду",
                EmailWork    = "*****@*****.**",
                LastName     = "Пупсиков",
                Name         = "Пупсик",
                PhoneMobile  = "+79999999999",
                SecondName   = "Пупсикович",
                Title        = "Пупсик хочет, чтобы ему перезвонили!",
                AssignedById = 1,
                StatusId     = "1"
            };

            var leadId = await client.CreateLead(lead);

            Assert.IsFalse(String.IsNullOrEmpty(leadId));
        }
예제 #3
0
 public async Task <string> CreateLead(BitrixLead lead)
 {
     return(await SendHttpPost(lead));
 }