private async Task <bool> AddUserToContactList(string email, string name) { var request = new MailjetRequest { Resource = Contact.Resource, ResourceId = ResourceId.Alphanumeric(email) }; var response = await _client.GetAsync(request); if (!response.IsSuccessStatusCode) { request = new MailjetRequest { Resource = Contact.Resource } .Property(Contact.Name, name) .Property(Contact.Email, email); response = await _client.PostAsync(request); if (response.IsSuccessStatusCode) { request = new MailjetRequest { Resource = Contact.Resource, ResourceId = ResourceId.Alphanumeric(email) }; response = await _client.GetAsync(request); } } if (response.IsSuccessStatusCode) { var contactId = response.GetData().First.Value <long>(Contact.ID); request = new MailjetRequest { Resource = Contactdata.Resource, ResourceId = ResourceId.Numeric(contactId) } .Property(Contactdata.Data, new JArray { new JObject { { "Name", "country" }, { "Value", CultureInfo.CurrentUICulture.Name } } }); response = await _client.PutAsync(request); if (response.IsSuccessStatusCode) { var contactListId = _mailSettings.Value.ContacListId.ContainsKey(CultureInfo.CurrentUICulture.Name) ? _mailSettings.Value.ContacListId[CultureInfo.CurrentUICulture.Name] : _mailSettings.Value.ContacListId["en-US"]; request = new MailjetRequest { Resource = ContactManagecontactslists.Resource, ResourceId = ResourceId.Numeric(contactId) } .Property(ContactManagecontactslists.ContactsLists, new JArray { new JObject { { "ListId", contactListId.ToString() }, { "Action", "addnoforce" } } }); response = await _client.PostAsync(request); if (response.IsSuccessStatusCode) { return(true); } else { _logger.LogError(response.GetErrorMessage()); } } else { _logger.LogError(response.GetErrorMessage()); } } else { _logger.LogError(response.GetErrorMessage()); } return(false); }