Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a campaign using an existing template #75

Closed
strigi opened this issue Aug 11, 2016 · 9 comments

Comments

Projects
None yet
4 participants
@strigi
Copy link

commented Aug 11, 2016

Hi,

I'm trying to figure out how to attach an existing template (by template_Id) to a new campaign and send it. I've tried Campaign.Setting.TemplateId with no luck.

I also tried setting campaign's content using Template.Id, after the campaign is created. Still, no luck.

This one doesn't work either:

var contentRequest = manager.Templates.GetAsync(_Template_Id);
Template _fetchedTemplate = contentRequest.Result;

var _result2 = manager.Content.AddOrUpdateAsync(_Campaign_Id, new MailChimp.Net.Core.ContentRequest { Template = _fetchedTemplate } );

Thanks!

@brandonseydel

This comment has been minimized.

Copy link
Owner

commented Aug 12, 2016

new ContentRequest{Template = new Template{
Id = yourTemplateId
}}
@dougvdotcom

This comment has been minimized.

Copy link
Contributor

commented Aug 13, 2016

On this subject: It would be helpful to implement template sections (that is, a Dictionary<string, string> for mc:edit fields in a template).

I can certainly see the value of sending static content via a template, but in many cases I need to customize some small part of the template to the user, e.g., add her name to the message; indicate a dynamically calculated date ("This offer expires on <mc:edit id="expireDate">", where expireDate = DateTime.UtcNow.AddDays(7)).

Thanks for a great library!

@dougvdotcom

This comment has been minimized.

Copy link
Contributor

commented Aug 14, 2016

Confirming this issue. Code below does not seem to generate exceptions, but it also fails to set the designated template as the campaign content.

var content = new ContentRequest
{
    Template = new Template
    {
        Id = 372497
    }
};

try
{
    await Manager.Content.AddOrUpdateAsync("89fe0e4766", content);
    return RedirectToAction("Detail");
}
catch (MailChimpException mce)
{
    return new HttpStatusCodeResult(HttpStatusCode.BadGateway, mce.Message);
}
catch (Exception ex)
{
    return new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, ex.Message);
}

A wild guess is that the Template model is not the same for PUT /campaigns/{campaign_id}/content as it is for {VERB} /templates/?{templateid}. In the former case one sends only an ID and optional sections; in the latter, one sends the ID and the HTML of the template.

It may be that because the objects are different, once sent to the MailChimp API, it is confused by the presence of illegitimate parameters and therefore fails silently.

Again, just a wild stab.

screenshot-us9 admin mailchimp com 2016-08-13 20-12-20

@strigi

This comment has been minimized.

Copy link
Author

commented Aug 14, 2016

@dougvdotcom thank you. Glad to know i was not imagining things. Either way i tried, i simply couldnt update a campign with a template.

@strigi

This comment has been minimized.

Copy link
Author

commented Aug 22, 2016

@brandonseydel Hi,
Any update on that? I experience the same results as @dougvdotcom
I even updated to the latest version, in case i missed anything.

Shouldn't it be possible to set the Template_Id when creating a new campaign, rather than updating an existing campaign? (not working either)

Campaign _campaign = new Campaign { Settings = new Setting { FromName = _FromName, TemplateId = _Template_Id, ReplyTo = _Address, SubjectLine = _Subject, InlineCss = true }, Type = CampaignType.Regular, Recipients = new MailChimp.Net.Models.Recipient { ListId = _List_Id, SegmentOptions = new SegmentOptions { SavedSegmentId = _Segment_Id } } }; IMailChimpManager manager = new MailChimpManager(MailChimpGridVariables.API_Key_Marketing); Campaign _result = await manager.Campaigns.AddAsync(_campaign);

image

@brandonseydel

This comment has been minimized.

Copy link
Owner

commented Aug 22, 2016

I bet it is sending default values for some of those booleans. I am creating ContentTemplate class stripped down and adding in missing query string parameters

@strigi

This comment has been minimized.

Copy link
Author

commented Aug 23, 2016

@brandonseydel was it helpful? :)
When do you think a new release is set?

@NoelOConnell

This comment has been minimized.

Copy link

commented Sep 21, 2016

I can confirm the same issue.

Adding [JsonProperty("template")] to Template in the ContentRequest resolved the issue.
Hope that helps.

dougvdotcom added a commit to dougvdotcom/MailChimp.Net that referenced this issue Sep 21, 2016

@dougvdotcom

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2016

Thanks @NoelOConnell and @brandonseydel

Pull request issued with noted fix.

dougvdotcom added a commit to dougvdotcom/MailChimp.Net that referenced this issue Jun 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.