Comments (10)
I was trying to do this as well and it looks like the current code doesn't support that. The .Subscribe(...)
method takes a strongly-typed "MergeVar" class, which you can extend from, but since it is downcasted when you pass it in the Json serializer will not pickup the ancestor properties.
I'd be interested in knowing what a good solution to this would be because I couldn't think of one right off.
from mailchimp.net.
I was able to get this working, but i'm unsure if the maintainer would choose to solve the problem in this way.
With these changes, you would be able to do something like
[DataContract]
public class CustomMergeVars: MergeVar
{
[DataMember(Name="FNAME")]
public string FirstName { get; set; }
[DataMember(Name="LNAME")]
public string LastName { get; set; }
}
then use it like
var email = new EmailParameter()
{
Email = "[email protected]"
};
var mergeVars = new CustomMergeVars
{
FirstName = "John",
LastName = "Doe"
};
var mc = new MailChimpManager("APIKey");
try
{
mc.Subscribe(listId: "listid",
emailParam: email,
mergeVars: mergeVars,
sendWelcome: true);
// redirect here
}
catch
{
// do something
}
and the resulting JSON request would look like
{
"apikey": "APIKey",
"id": "listid",
"email": {
"email": "[email protected]"
},
"merge_vars": {
"FNAME": "John",
"LNAME": "Doe"
},
"email_type": "html",
"double_optin": true,
"update_existing": false,
"replace_interests": true,
"send_welcome": true
}
I'm using this so I've verified it works for my needs
from mailchimp.net.
i actually ended up using my own classes in the end as, as you point out the mergevar class here doesn't seem finished.
for my mergevar class i used
internal class MergeVars : Dictionary<string, object>
{
/// <summary>
/// Initializes a new instance of the <see cref="MergeVars"/> class.
/// </summary>
public MergeVars()
{
this.Add("new-email", null);
this.Add("groupings", null);
}
/// <summary>
/// set this to change the email address. This is only respected on calls using update_existing or
/// when passed to listUpdateMember().
/// </summary>
public string NewEmail
{
get
{
return (string) this["new-email"];
}
set
{
this["new-email"] = value;
}
}
/// <summary>
/// Interest Groupings
/// </summary>
public List<Grouping> Groupings
{
get
{
return (List<Grouping>)this["groupings"];
}
set
{
this["groupings"] = value;
}
}
}
however there are some problems with this. I couldn't get serilization of the grouping class to recognise datamember names so had to end up using lower-case property names for the Grouping class. Not ideal. So I am sure that there is a better solution out there.
As the mergevars is a dictionary, any mergevar can now be added as required.
from mailchimp.net.
@chadxz Thanks for the reply. To be honest, it's not clear to me how mergevars should work, so I wanted to tackle other parts of the API before coming back around to them. I'll review your pull request.
from mailchimp.net.
I'm having this issue as well. I'm using .Net 4.0. I changed the Target Framework to be 4.0 for MailChimp and the MailChimp.Tests projects. First name and last name aren't showing up in MailChimp. The subscriber email address is added to the list just fine.
I altered SubscribeWithGroupSelection_Successful to make this call:
EmailParameter results = mc.Subscribe(strListID, email, mvso, "html" ,false, false, false, false);
The only thing I changed in the test was to pass in the other parameters to avoid the opt-in email. Do I have to download ServiceStack and recompile that too?
from mailchimp.net.
Can you post a failing test?
from mailchimp.net.
The test doesn't fail. It simply doesn't store first or last name in the
mailchimp site.
On Jan 16, 2015 2:36 AM, "Marco Dissel" [email protected] wrote:
Can you post a failing test?
—
Reply to this email directly or view it on GitHub
#5 (comment)
.
from mailchimp.net.
Are you sure? (the fieldnames FNAME and LNAME are required in the first list in your account for a successful test)
I just re-run the test in my account and the fields are properly updated
from mailchimp.net.
I'm sure. I went into my list definition on the site and marked these two
fields as REQUIRED and an error came back from the json call reporting
this, as expected.
I suspect that the service stack call is not parsing out the properties for
first and last name.
On Jan 16, 2015 3:23 AM, "Marco Dissel" [email protected] wrote:
Are you sure? (the fieldnames FNAME and LNAME are required in the first
list in your account for a successful test)
I just re-run the test in my account and the fields are properly updated—
Reply to this email directly or view it on GitHub
#5 (comment)
.
from mailchimp.net.
I wrote an article on a simple way up adding subscribers to a list using:
Dim mailchimp As New ZmailChimp
Dim ListId$ = "9b2e63f0b9" 'List Sage' List
Dim email$ = "[email protected]" '"[email protected]"
Dim fieldListOnAdd = "FNAME,Sam,LNAME,Smith,MTYPE,User,MID,631637"
Dim fieldListOnUpdate = "FNAME,Sam,LNAME,Smith,MID,631637" 'Don't change MTYPE
'Put on 'Sage One' and 'Sage 50' group
Dim groupList = "407da9f47d,05086211ba"
With mailchimp
.API$ = "46cMailChimpAPIKeyd1de-us14" 'MailChimp API key
.dataCenter$ = "us14" 'Last 4 letters of API key
.password$ = "Password!"
MsgBox(.addSubscriber(ListId$, email, fieldListOnAdd, fieldListOnUpdate, groupList))
End With
mailchimp = Nothing
see:http://www.codeproject.com/Tips/1140339/Mail-Chimp-Add-Update-e-mail-to-List-and-Subscribe
this may save someone some time
from mailchimp.net.
Related Issues (20)
- Moving forward to Api 3? HOT 3
- Groupings and GroupInterests
- Issues for subscribing to a list HOT 4
- Cannot Add to GAC HOT 2
- List<BatchEmailParameter> Error while webservice call HOT 1
- .NET Wrapper for the MailChimp v3.0 API HOT 4
- CampaignListResult_GetCampaigns does not provides absplit campaign
- CampaignListResult_GetCampaigns does not provides absplit campaign HOT 1
- How do i get template.default-content
- Issue with Template Id
- Deleting Lists
- Array is not a valid interest group HOT 1
- System.Runtime.Serialization.SerializationException HOT 2
- Subscribe don't work HOT 1
- ServiceStack.Text HOT 1
- Language field at AddSegment HOT 2
- How does one loop your expcetions
- AddStaticSegmentMembers with more than 20K emails results in timeout HOT 1
- Unable to see subscribed contact in the list.
- Send emails over api HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mailchimp.net.