/// <summary> /// Reads contacts from bronto using a filter and the specified return fields and information /// </summary> /// <param name="filter">The filter to use when reading</param> /// <param name="options">The fields and information to return. Use the extension methods on the readDeliveries class to specify options</param> /// <returns>the list of contacts</returns> public List <deliveryObject> Read(deliveryFilter filter, readDeliveries options = null) { if (filter == null) { throw new ArgumentNullException("filter", "The filter must be specified. Alternatively call the Read() function"); } using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { readDeliveries c = options ?? new readDeliveries(); c.filter = filter; c.pageNumber = 1; List <deliveryObject> list = new List <deliveryObject>(); deliveryObject[] result = client.readDeliveries(session.SessionHeader, c); if (result != null) { list.AddRange(result); } while (result != null && result.Length > 0) { c.pageNumber += 1; result = client.readDeliveries(session.SessionHeader, c); if (result != null) { list.AddRange(result); } } return(list); } }
/// <summary> /// Reads contacts from bronto using a filter and the specified return fields and information /// </summary> /// <param name="filter">The filter to use when reading</param> /// <param name="options">The fields and information to return. Use the extension methods on the readMessages class to specify options</param> /// <returns>the list of contacts</returns> public async Task <List <messageObject> > ReadAsync(messageFilter filter, readMessages options = null) { if (filter == null) { throw new ArgumentNullException("filter", "The filter must be specified. Alternatively call the Read() function"); } using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { readMessages c = options ?? new readMessages(); c.filter = filter; c.pageNumber = 1; List <messageObject> list = new List <messageObject>(); readMessagesResponse response = await client.readMessagesAsync(session.SessionHeader, c); messageObject[] result = response.@return; if (result != null) { list.AddRange(result); } while (result != null && result.Length > 0) { c.pageNumber += 1; response = await client.readMessagesAsync(session.SessionHeader, c); result = response.@return; if (result != null) { list.AddRange(result); } } return(list); } }
/// <summary> /// Add or updates a list of contacts in Bronto /// </summary> /// <param name="contact">The contacts to add or update</param> /// <returns>The result of the add or update operation <seealso cref="BrontoResult"/></returns> public BrontoResult AddOrUpdateIncremental(IEnumerable <contactObject> contacts) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { foreach (contactObject contact in contacts) { var address = new stringValue { value = contact.email }; var emailAddressArray = new[] { address }; var filter = new contactFilter { email = emailAddressArray }; var options = new readContacts() { includeLists = true, includeListsSpecified = true }; var readResults = Read(filter, options); var existingContact = readResults.FirstOrDefault(); if (existingContact != null) { contact.listIds = contact.listIds.Concat(existingContact.listIds).ToArray(); } } writeResult response = client.addOrUpdateContacts(session.SessionHeader, contacts.ToArray()); return(BrontoResult.Create(response)); } }
public BrontoResult Add(IEnumerable <deliveryObject> deliveries) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { writeResult response = client.addDeliveries(session.SessionHeader, deliveries.ToArray()); return(BrontoResult.Create(response)); } }
public BrontoResult Delete(IEnumerable <mailListObject> mailLists) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { writeResult response = client.deleteLists(session.SessionHeader, mailLists.ToArray()); return(BrontoResult.Create(response)); } }
/// <summary> /// Updates a list of contacts in Bronto /// </summary> /// <param name="contacts">the list of contacts to update</param> /// <returns>The result of the add operation <seealso cref="BrontoResult"/></returns> public BrontoResult Update(IEnumerable <contactObject> contacts) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { writeResult response = client.updateContacts(session.SessionHeader, contacts.ToArray()); return(BrontoResult.Create(response)); } }
public async Task <BrontoResult> DeleteAsync(IEnumerable <mailListObject> mailLists) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { deleteListsResponse response = await client.deleteListsAsync(session.SessionHeader, mailLists.ToArray()); return(BrontoResult.Create(response.@return)); } }
/// <summary> /// Add or updates a list of contact in Bronto /// </summary> /// <param name="contact">The contacts to add or update</param> /// <returns>The result of the add or update operation <seealso cref="BrontoResult"/></returns> public async Task <BrontoResult> AddOrUpdateAsync(IEnumerable <contactObject> contacts) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { addOrUpdateContactsResponse response = await client.addOrUpdateContactsAsync(session.SessionHeader, contacts.ToArray()); return(BrontoResult.Create(response.@return)); } }
/// <summary> /// Creates a new Login session /// </summary> /// <param name="ApiToken">A valid API token. See dev.bronto.com for details</param> /// <returns>The Login session</returns> public static async Task <LoginSession> CreateAsync(string ApiToken) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create()) { LoginSession login = new LoginSession(); loginResponse response = await client.loginAsync(ApiToken); login.SessionId = response.@return; return(login); } }
/// <summary> /// Creates a new Login session /// </summary> /// <param name="ApiToken">A valid API token. See dev.bronto.com for details</param> /// <returns>The Login session</returns> public static LoginSession Create(string ApiToken) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create()) { LoginSession login = new LoginSession() { SessionId = client.login(ApiToken) }; return(login); } }
/// <summary> /// Creates a new Login session /// </summary> /// <param name="ApiToken">A valid API token. See dev.bronto.com for details</param> /// <returns>The Login session</returns> public static LoginSession Create(string ApiToken) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create()) { LoginSession login = new LoginSession() { SessionId = client.login(ApiToken) }; return(login); } }
/// <summary> /// Adds a list of contacts to a mailing list /// </summary> /// <param name="list">the list to add</param> /// <param name="contacts">the list of contacts to add</param> /// <returns>The result of the addToList operation <seealso cref="BrontoResult"/></returns> public BrontoResult AddToList(mailListObject list, contactObject[] contacts) { using (BrontoSoapPortTypeClient client = BrontoSoapClient.Create(Timeout)) { addToList addToList = new addToList() { list = list, contacts = contacts }; writeResult response = client.addToList(session.SessionHeader, addToList); return(BrontoResult.Create(response)); } }
public void Send() { /////////////////////////////////////////////////////////////////// // // login, which creates the requisite header // /////////////////////////////////////////////////////////////////// sessionHeader header = new sessionHeader(); BrontoSoapPortTypeClient client = new BrontoSoapPortTypeClient(); header.sessionId = client.login(ConfigurationManager.AppSettings[GetType().Name]); /////////////////////////////////////////////////////////////////// // // add recipients to contact list // /////////////////////////////////////////////////////////////////// List<contactObject> contactValues = new List<contactObject>(); foreach(string email in To) { contactObject co = new contactObject(); co.email = email; contactValues.Add(co); } writeResult contacts = client.addOrUpdateContacts(header, contactValues.ToArray()); /////////////////////////////////////////////////////////////////// // // using list of contacts, create list of recipients // /////////////////////////////////////////////////////////////////// List<deliveryRecipientObject> recipients = new List<deliveryRecipientObject>(); foreach(resultItem item in contacts.results) { deliveryRecipientObject recipient = new deliveryRecipientObject(); recipient.type = "contact"; recipient.id = item.id; recipients.Add(recipient); } /////////////////////////////////////////////////////////////////// // // add email to message list // /////////////////////////////////////////////////////////////////// messageContentObject mco = new messageContentObject(); mco.subject = Subject; mco.content = Body.Replace("\r\n", "<br>"); mco.type = "html"; messageObject mo = new messageObject(); mo.name = string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now); mo.content = new messageContentObject[] { mco }; writeResult messages = client.addMessages(header, new messageObject[] { mo }); /////////////////////////////////////////////////////////////////// // // using list of messages, create list of deliveries // /////////////////////////////////////////////////////////////////// List<deliveryObject> deliveries = new List<deliveryObject>(); foreach(resultItem item in messages.results) { deliveryObject delivery = new deliveryObject(); delivery.start = DateTime.Now; delivery.startSpecified = true; delivery.messageId = item.id; delivery.fromEmail = From; delivery.fromName = From.Substring(0, From.IndexOf('@')); delivery.recipients = recipients.ToArray(); deliveries.Add(delivery); } // send the deliveries! client.addDeliveriesAsync(header, deliveries.ToArray()); }
public IEnumerable<IMetricsProvider> GetMetrics(int days) { /////////////////////////////////////////////////////////////////// // // Instantiate the client // /////////////////////////////////////////////////////////////////// sessionHeader header = new sessionHeader(); BrontoSoapPortTypeClient client = new BrontoSoapPortTypeClient(); header.sessionId = client.login(ConfigurationManager.AppSettings[GetType().Name]); /////////////////////////////////////////////////////////////////// // // Retrieve the contact for which you need the metrics. // /////////////////////////////////////////////////////////////////// contactFilter cf = new contactFilter(); cf.id = new string[] { "4a8e4dc1-e38f-438b-b8b5-75e46799bc9c" }; readContacts rc = new readContacts(); rc.filter = cf; contactObject[] co = client.readContacts(header, rc); contactObject mycontact = co[0]; /////////////////////////////////////////////////////////////////// // // Create a deliverFilter and read all deliverObjects // /////////////////////////////////////////////////////////////////// deliveryFilter df = new deliveryFilter(); df.deliveryType = new string[] { "normal","test","automated","split","transactional","triggered" }; readDeliveries rd = new readDeliveries(); rd.filter = df; deliveryObject[] dos = client.readDeliveries(header, rd); /////////////////////////////////////////////////////////////////// // // Extract deliverObjects into ProviderMetrics // /////////////////////////////////////////////////////////////////// List<IMetricsProvider> list = new List<IMetricsProvider>(); try { foreach (deliveryObject doj in dos) { ProviderMetrics item = new ProviderMetrics(); //deliveryRecipientObject[] dro = doj.recipients; // id can be contact id, list id or segment id //dro[0].id // if contactId, there are metrics by contact, but that doesn't tell the full story /* deliveryRecipientFilter drf = new deliveryRecipientFilter(); drf.deliveryId = doj.id; readDeliveryRecipients rdr = new readDeliveryRecipients(); rdr.filter = drf; deliveryRecipientStatObject[] drso = client.readDeliveryRecipients(header, rdr); */ // Once we receive the deliveryRecipientStatObject, we have to check // if this object has click/send/bounce and store the contactId accordingly item.Name = doj.messageId; item.Bounces = (int)doj.numBounces; item.Clicks = (int)doj.numClicks; item.Opens = (int)doj.numOpens; item.Sends = (int)doj.numSends; // read unsubscribes unsubscribeFilter uf = new unsubscribeFilter(); uf.deliveryId = doj.id; readUnsubscribes ru = new readUnsubscribes(); ru.filter = uf; ru.pageNumber = 1; if (client.readUnsubscribes(header, ru) == null) item.Unsubscribes = 0; else item.Unsubscribes = client.readUnsubscribes(header, ru).Length; list.Add(item); } } catch (Exception e) { MessageBox.Show(e.Message); ProviderMetrics item = new ProviderMetrics(); item.Name = "null"; item.Bounces = 0; item.Clicks = 0; item.Opens = 0; item.Sends = 0; item.Unsubscribes = 0; list.Add(item); } return list; }