I'm sorry for starting this thread as i'm aware there's a similar thread available (http://forums.asp.net/p/1488091/4174248.aspx) however as i'm still a newbie and i have a very limited knowledge i tried to read and implement the documentation from http://perceptivemcapi.codeplex.com/
which can also be found from http://www.mailchimp.com/api/gettingstarted/, but i still couldn't get it to worked.
The problem is i don't know where to start and where to put the wrapper, code, etc and with my limited knowledge i created this:
Download File Here.
In summary:
1. firstly i created bin folder and put the CookComputing.XmlRpcV2.dll and PerceptiveMCAPI.dll there and reference them.
2. I created App_Code folder and create 2 vb there with a name listBatchSubscribe.vb and Lists.vb and here are the codes:
listBatchSubscribe.vb Code:
Imports Microsoft.VisualBasic
Imports PerceptiveMCAPI
Imports PerceptiveMCAPI.Methods
Imports PerceptiveMCAPI.Types
Imports System.Configuration
Imports System.Web
Public Class listBatchSubscribe
Public Sub listBatchSubscribe_method(ByVal SubscriberList As List(Of Subscriber))
Dim input As listBatchSubscribeInput = New listBatchSubscribeInput()
' any directive overrides
input.api_Validate = True
input.api_AccessType = EnumValues.AccessType.Serial
input.api_OutputType = EnumValues.OutputType.JSON
' method parameters
input.parms.apikey = MCAPISettings.default_apikey
input.parms.id = "YourListId"
input.parms.double_optin = False
input.parms.replace_interests = True
input.parms.update_existing = True
'
Dim batch As List(Of Dictionary(Of String, Object)) = _
New List(Of Dictionary(Of String, Object))
For Each sub_rec As Subscriber In SubscriberList
Dim entry As Dictionary(Of String, Object) = _
New Dictionary(Of String, Object)
entry.Add("EMAIL", sub_rec.email)
entry.Add("EMAIL_TYPE", sub_rec.email_type)
entry.Add("FNAME", sub_rec.first_name)
entry.Add("LNAME", sub_rec.last_name)
Dim next_payment As DateTime = sub_rec.last_payment.AddMonths(1)
entry.Add("NEXTPAY", next_payment)
batch.Add(entry)
Next
input.parms.batch = batch
' execution
Dim cmd As listBatchSubscribe = New listBatchSubscribe(input)
Dim output As listBatchSubscribeOutput = cmd.Execute()
' output, format with user control
If output.api_ErrorMessages.Count > 0 Then
' raw data & errors
showresults(output.api_Request, output.api_Response, _
output.api_ErrorMessages, output.api_ValidatorMessages)
Else
show_listBatch1.Display(output)
End If
End Sub
End Class
Lists.vb Code:
Imports Microsoft.VisualBasic
Imports PerceptiveMCAPI
Imports PerceptiveMCAPI.Methods
Imports PerceptiveMCAPI.Types
Imports System.Configuration
Imports System.Web
Public Class Lists
' A real simple request (using all default settings)
Public Sub lists_method()
' input parameters, using default apikey
Dim input As listsInput = New listsInput(MCAPISettings.default_apikey)
' execution
Dim cmd As lists = New lists(input)
Dim output As listsOutput = cmd.Execute()
' format output (Assuming a User control named show_lists)
show_lists1.Display(output)
End Sub
End Class
3. I put this vb code in the Default.aspx page:
Imports PerceptiveMCAPI
Imports PerceptiveMCAPI.Methods
Imports PerceptiveMCAPI.Types
Imports System.Configuration
Imports System.Web
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim apikey As String = "myAPI-KEY" ' or default to config
GridView1.DataSource = MCAPISettings.ListAPISettings().ToList()
GridView1.DataBind()
End Sub
End Class
I know it still doesn't make sense here and there, however i truly have no idea and i'd really need your help.
I truly appreciate if there's anyone who can give me a sample on how to implement it i'd truly appreciate it. I truly need a guideline as i've been spending a whole day yesterday trying to figure out and find any information that can help me but it still
gets me nowhere.
Basically what i'd like to achieve from the mailchimp API is an ability to get contact details from my sql server database and send an email to them right from my site.
Hopefully i make myself clear and i truly appreciate your help and guideline.
I am writing something almost exactly the same. Just posted in here too.
Did you ever solve it?
Here's what I have so far.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.IO;
using PerceptiveMCAPI;
using PerceptiveMCAPI.Methods;
using PerceptiveMCAPI.Types;
using PerceptiveMCAPI.Types.Internal;
namespace MailChimpAPI_Csharp
{
class Program
{
static void Main(string[] args)
{
//The following qstring find those who registered
//but either never purchased or returned/voided/frauded and never re-purchased
string connectionString = GetConnectionString();
string queryString =
"SELECT DISTINCT Customer.Email, Customer.FirstName, Customer.LastName "+
"FROM Customer " +
"WHERE NOT EXISTS " +
"(SELECT * FROM Orders " +
"WHERE Customer.CustomerID = Orders.CustomerID AND " +
"(Orders.RefundedOn IS NULL) AND (Orders.VoidedOn IS NULL) AND " +
"(Orders.FraudedOn IS NULL) AND (Orders.AuthorizedOn IS NOT NULL)) AND " +
"Customer.Email <>'' AND " +
"Customer.Email is not null";
using (OleDbConnection connection =
new OleDbConnection(connectionString))
{
OleDbCommand command = connection.CreateCommand();
command.CommandText = queryString;
try
{
connection.Open();
OleDbDataReader reader = command.ExecuteReader();
//=========================================================================================================
//I know the following is all jumbled up.
//I was using different source examples and got lost in it all..
//it's supposed to match
//public void listBatchSubscribe_method(List<Subscriber> SubscriberList) near the bottom
//==========================================================================================================
using (reader)
{
System.Collections.Generic.List<MailChimpList> arrObjects = new System.Collections.Generic.List<MailChimpList>();
List<MailChimpList> student = new List<MailChimpList>();
int customerId = reader.GetOrdinal("customerId "); //obviously this needs massaging...but how?
int CustomerName = reader.GetOrdinal("CustomerName "); //obviously this needs massaging...but how?
while (reader.Read())
{
CustomerEntity obj = new CustomerEntity();
obj.customerId = (reader[customerId] != Convert.DBNull) ? reader[customerId].ToString() : null;
obj.CustomerName = (reader[CustomerName] != Convert.DBNull) ? reader[CustomerName].ToString() : null;
arrObjects.Add(obj);
}
}
//==================================================
while (reader.Read())
{
//build a list of users from the DB to update in listbatchsubscribe
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
//=======================================================================================
//then use this folowing listbatchsubscribe from PerceptiveMCAPI
// A little more intense request (listBatchSubscribe using Serial/JSON)
// assumes a collection was created elsewhere from database info
// with email, email_type, first name, last name, and last_payment
public void listBatchSubscribe_method(List<Subscriber> SubscriberList)
{
listBatchSubscribeInput input = new listBatchSubscribeInput();
// any directive overrides
input.api_Validate = true;
input.api_AccessType = EnumValues.AccessType.Serial;
input.api_OutputType = EnumValues.OutputType.JSON;
// method parameters
input.apikey = MCAPISettings.default_apikey;
input.id = "YourListId";
input.double_optin = false;
input.replace_interests = true;
input.update_existing = true;
//
List<Dictionary<string, object>> batch =
new List<Dictionary<string, object>>();
foreach (Subscriber sub_rec in SubscriberList)
{
Dictionary<string, object> entry = new Dictionary<string, object>();
entry.Add("EMAIL", sub_rec.email);
entry.Add("EMAIL_TYPE", sub_rec.email_type);
entry.Add("FNAME", sub_rec.first_name);
entry.Add("LNAME", sub_rec.last_name);
DateTime next_payment = sub_rec.last_payment.AddMonths(1);
entry.Add("NEXTPAY", next_payment);
batch.Add(entry);
}
input.batch = batch;
// execution
listBatchSubscribe cmd = new listBatchSubscribe(input);
listBatchSubscribeOutput output = cmd.Execute();
// output, format with user control
if (output.api_ErrorMessages.Count > 0)
{
showResults(output.api_Request, output.api_Response, // raw data
output.api_ErrorMessages, output.api_ValidatorMessages); // & errors
}
else
{
show_listBatch1.Display(output);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
// Assumes Northwind.mdb is located in the c:\Data folder.
//I will change this to use an external text file later================
//TESTING ONLY!!!!!!!!!!!1=============================================
return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ "c:\\Data\\Northwind.mdb;User Id=admin;Password=;";
}
}
}
I had to change the project properties to use the full .NET 4.0 framework and not the 4 client profile... now the references work, but I'm getting errors in the name of the lists.
example error for list 'subscriber'...
Error 1 The type or namespace name 'Subscriber' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Beau D'Amore\Documents\Console Apps\MailChimpAPI-Csharp\MailChimpAPI-Csharp\Program.cs 90 52 MailChimpAPI-Csharp
P.S. I'm writing it as a console app FYI
i want to know that if i want to check the "ClickStatus" "Total Number of Suscribers" etc etc than how could i add this functionality in my code:
For now i have the following code:
public bool SubscribeToList(string EmailAddress, string FirstName, string LastName, string Subject, string Body, string EmailFrom, string DisplayName)
{
listSubscribeInput input = new listSubscribeInput();
input.api_AccessType = PerceptiveMCAPI.EnumValues.AccessType.Serial;
input.api_CustomErrorMessages = true;
input.parms.email_address = EmailAddress;
input.parms.send_welcome = true;
input.parms.update_existing = false;
input.parms.replace_interests = true;
input.parms.double_optin = false;
input.parms.merge_vars.Add("FNAME", FirstName);
input.parms.merge_vars.Add("LNAME", LastName);
input.api_MethodType = PerceptiveMCAPI.EnumValues.MethodType.POST;
input.api_Validate = true;
input.api_OutputType = PerceptiveMCAPI.EnumValues.OutputType.XML;
input.parms.apikey = Common.GetVariableByKey(VariableKey.MailChimpAPIKey); //System.Configuration.ConfigurationSettings.AppSettings["MailChimpApiKey"].ToString(); input.parms.id = List();
listSubscribe Subscribe = new listSubscribe();
listSubscribeOutput output = Subscribe.Execute(input);
Member
2 Points
24 Posts
MailChimp API
May 05, 2011 09:00 PM|stefanto|LINK
Hi,
I'm sorry for starting this thread as i'm aware there's a similar thread available (http://forums.asp.net/p/1488091/4174248.aspx) however as i'm still a newbie and i have a very limited knowledge i tried to read and implement the documentation from http://perceptivemcapi.codeplex.com/ which can also be found from http://www.mailchimp.com/api/gettingstarted/, but i still couldn't get it to worked.
The problem is i don't know where to start and where to put the wrapper, code, etc and with my limited knowledge i created this: Download File Here.
In summary:
1. firstly i created bin folder and put the CookComputing.XmlRpcV2.dll and PerceptiveMCAPI.dll there and reference them.
2. I created App_Code folder and create 2 vb there with a name listBatchSubscribe.vb and Lists.vb and here are the codes:
listBatchSubscribe.vb Code:
Lists.vb Code:
3. I put this vb code in the Default.aspx page:
4. And i add this code on the web.config
I know it still doesn't make sense here and there, however i truly have no idea and i'd really need your help.
I truly appreciate if there's anyone who can give me a sample on how to implement it i'd truly appreciate it. I truly need a guideline as i've been spending a whole day yesterday trying to figure out and find any information that can help me but it still gets me nowhere.
Basically what i'd like to achieve from the mailchimp API is an ability to get contact details from my sql server database and send an email to them right from my site.
Hopefully i make myself clear and i truly appreciate your help and guideline.
Thank you and kind regards,
Stefanto
Member
2 Points
24 Posts
Re: MailChimp API
May 15, 2011 08:50 PM|stefanto|LINK
Anyone?
Member
40 Points
295 Posts
Re: MailChimp API
Jun 09, 2011 01:16 PM|Beau_Damore|LINK
I am writing something almost exactly the same. Just posted in here too.
Did you ever solve it?
Here's what I have so far.
Consultant
www.beaudamore.com
Member
2 Points
24 Posts
Re: MailChimp API
Jul 04, 2011 09:20 PM|stefanto|LINK
Hi Beaue, thanks for your help however i've posted a thread on the PercetiveMCAPI discussion board and jonHierro there helped me solved it.
Here's the link to the discussion:
http://perceptivemcapi.codeplex.com/discussions/257461
Thanks :)
Member
40 Points
295 Posts
Re: MailChimp API
Jul 06, 2011 09:14 AM|Beau_Damore|LINK
Thanks! I've actually got it all working great. If you want some code, lemme know.
Consultant
www.beaudamore.com
Member
101 Points
393 Posts
Re: MailChimp API
Oct 21, 2011 06:01 AM|mmazeemahmad|LINK
Hi
Beau_Damore
i want to know that if i want to check the "ClickStatus" "Total Number of Suscribers" etc etc than how could i add this functionality in my code:AccessType.Serial;FNAME", FirstName);LNAME", LastName);MethodType.POST;OutputType.XML;VariableKey.MailChimpAPIKey); //System.Configuration.ConfigurationSettings.AppSettings["MailChimpApiKey"].ToString();
Count > 0)FirstOrDefault().code;FirstOrDefault().error;
For now i have the following code:
public bool SubscribeToList(string EmailAddress, string FirstName, string LastName, string Subject, string Body, string EmailFrom, string DisplayName)
{
listSubscribeInput input = new listSubscribeInput();
input.api_AccessType = PerceptiveMCAPI.EnumValues.
input.api_CustomErrorMessages = true;
input.parms.email_address = EmailAddress;
input.parms.send_welcome = true;
input.parms.update_existing = false;
input.parms.replace_interests = true;
input.parms.double_optin = false;
input.parms.merge_vars.Add("
input.parms.merge_vars.Add("
input.api_MethodType = PerceptiveMCAPI.EnumValues.
input.api_Validate = true;
input.api_OutputType = PerceptiveMCAPI.EnumValues.
input.parms.apikey = Common.GetVariableByKey(
input.parms.id = List();
listSubscribe Subscribe = new listSubscribe();
listSubscribeOutput output = Subscribe.Execute(input);
if (output.api_ErrorMessages.
{
ErrorCode = output.api_ErrorMessages.
Error = "Error occured. " + output.api_ErrorMessages.
return false;
}
return output.result;
}
Do you have a code for this???????