cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Content via C# CTCT Wrapper

Occasional Advisor

Dynamic Content via C# CTCT Wrapper

I've looked over the "guide" (https://developer.constantcontact.com/docs/developer-guides/custom-content.html) but it seems to be a contrived example. I've used the CTCT API before without issue for example end-users can update their preference list and the API to send campaigns. I've looked at the UnitTest from github but I don't see anything that helps.

 

What I need to do now is to create a campaing utilizing data from our db and have our data reflected in the campaign for the respective subscriber where the email matches. The "steps" in the guide are not clicking. The only option I can see where this would work is to create a campaign for each user in a foreach (ouch) and then apply my data in the TextContent and EmailContent property of the EmailCampaign object.

 

Please advise with steps that are more clear or what I'm missing. Thanks,

 

Attached is a result of when I put the campaign object in a foreach but as you know this is not ideal since it creates a campaign for each subscriber. 

 

Here's what I'd like to do:

 

try
{
EmailCampaign campaign = new EmailCampaign
{
EmailContentFormat = CampaignEmailFormat.HTML,
TextContent = "text table will be",
EmailContent = "<html><body>Test, $Subscriber.CustomText1 $Subscriber.CustomText2 $Subscriber.CustomText3  $Subscriber.CustomText4</body></html>",
FromName = "Outbid Notifications",
FromEmail = "jquinones@myemail.com",
Subject = "Outbid Notifications",
Name = String.Format("Test Outbid Notificaton {0}", DateTime.Now),
ReplyToEmail = "jquinones@myemailcom",

Lists = sentContactLists,
MessageFooter = new MessageFooter
{
AddressLine1 = "2nd Street West",
City = "City",
Country = "IL",
OrganizationName = "Our Company"
}
};

EmailCampaign savedCampaign = _constantContact.AddCampaign(campaign);


constant_contact_result.PNG
8 REPLIES 8
Moderator

Re: Dynamic Content via C# CTCT Wrapper

Hi Dan, 

 

Yes, the example provided demonstrated how to merge content specific to each user into an email campaign using custom_fields in the contact, and variables to pull in that content into the email campaign. I can tell you the general steps to get content from your database into a contact record. It'll take longer for me to come up with php code using our SDK to accomplish the process.

 

  1. Assemble the contact information, including the contact-specific information from your database into a table that uses the column headings listed here.
    Each element of custom content needs to be in a separate column labeled Custom Field n, Custom Field n+1, etc. Export your table to a JSON or .CSV formatted file.
  2. I'm assuming that the number of contacts/subscribers is fairly large, so construct a call to either the import contact bulk activity or import contact multipart bulk activity endpoint.
    Corresponding .net SDK methods: AddContacts.csAddContactsImportData.cs.
  3. Upon a successful import contacts bulk activity call, each contact will now have the custom content for the Lot, Bid Status, Current High Bid in Custom Field 1, 2, and 3, for example. 
    When the campaign you've created is run, the Custom Field values for in the contact record will display where the $Subscriber.CustomTextN variable is placed in the body of the campaign.

Stay tuned for code examples.

 

Let me know if this is helpful, or you already understand this, and need something else.

 

Regards, 

Rich Marcucella
Sr. Technical Writer, Content Developer
Web Services Team
http://developer.constantcontact.com
Occasional Advisor

Re: Dynamic Content via C# CTCT Wrapper

Maybe it's the verbiage used but one thing throwing me off is that I'm not adding a contact but using existing contacts and appending existing values. For example we have an outbid notification list that can have 5,134 subscribers. Those subscribers exist both in Constant Contact and our DB. I match the emails of those that subscribed in CC with our user data and append the data to submit to CC. So were not creating new accounts but want to merge custom data into the CustomTextN fields. Is this just a terminology thing and does your recommendation take this into account?

 

Look forward to the examples.

Moderator

Re: Dynamic Content via C# CTCT Wrapper

See the updated original response...my apologies for mixing up languages.

Rich Marcucella
Sr. Technical Writer, Content Developer
Web Services Team
http://developer.constantcontact.com
Occasional Advisor

Re: Dynamic Content via C# CTCT Wrapper

I'll work on this to see what I come up with. Thanks for the timely responses!

Moderator

Re: Dynamic Content via C# CTCT Wrapper

Read the documentation for the Import Contact bulk activity endpoint here. It's used to both add new contacts, and update existing contacts. 

Rich Marcucella
Sr. Technical Writer, Content Developer
Web Services Team
http://developer.constantcontact.com
Occasional Advisor

Re: Dynamic Content via C# CTCT Wrapper

Initally, one thing that I'm not sure will work looking at the JSON custom_fields is to have an array of custom_fields nested in custom_fields to populate a table? This is a small example as many of our customers could bid on over a hundred lots and a the subscriber may have 50 or more outbid lots. Conceptually, I'll need to be able to do something like this:

 

"custom_fields": [{

  "custom_fields": [{

  "name": "Lot",
  "value": "1"
  }, {
  "name": "Bid Status",
  "value": "Outbid"
  },{

  "name": "Bid Amount",
  "value": "250.00"
  }],

  "custom_fields": [{

  "name": "Lot",
  "value": "2"
  }, {
  "name": "Bid Status",
  "value": "Tied"
  },{

  "name": "Bid Amount",
  "value": "500.00"
  }],

  "custom_fields": [{

  "name": "Lot",
  "value": "45"
  }, {
  "name": "Bid Status",
  "value": "Outbid"
  },{

  "name": "Bid Amount",
  "value": "2300.00"
  }]

}]

 

Then in the mark up the subscriber could view the table as such:

Lot | Bid Status | Bid Amount

1    |   Outbid     |  250.00  

2    |     Tied      |  500.00  

45  |   Outbid     |  2300.00  

Moderator

Re: Dynamic Content via C# CTCT Wrapper

Hi - I strongly encourage you to read the bulk import endpoint documentation if you have not already.

 

  1. The API only supports custom field named CustomField1, CustomField2, upto CustomField15. The product UI now supports very flexible naming of custom fields, but the API does not at this time: From the documentation:

custom_fields

array

You can create up to 15 custom fields for a contact. The API currently only supports the custom field format described here. If the account uses the new contact management system, it is possible to create custom fields with varying formats. The API ignores custom fields not using the format below.

label

string (50)

For accounts using the new contacts management system, this read-only field displays the custom_field name entered using the product GUI. For accounts using the legacy contact management system, the value is displayed only if it matches the CustomFieldnn (n=1-15) format. (Read Only)

name

string

You must name each custom field CustomField1, CustomField2,...CustomField15. Only custom fields with values are shown in response to a GET call.

value

string (50)

Content of the custom field

 

2. The labels for the 3 fields you are presenting are static, not dynamic, so they should be included in the campaign in the email_content property. Otherwise they use up 3 of the 15 custom_fields available for each contact. In your model, you can only display 5 bid status for each contact (5 items x 3 fields each =15.)

 

3. The JSON for your example should look like this:

"custom_fields": [{
  "name": "CustomField1",
  "value": "1"
  }, {
  "name": "CustomField2",
  "value": "Outbid"
  },{
  "name": "CustomField3",
  "value": "250.00"
  },
  {
  "name": "CustomField4",
  "value": "2"
  }, {
  "name": "CustomField5",
  "value": "Tied"
  },{
  "name": "CustomField6",
  "value": "500.00"
  },
  {
  "name": "CustomField7",
  "value": "45"
  }, {
  "name": "CustomField8",
  "value": "Outbid"
  },{
  "name": "CustomField9",
  "value": "2300.00"
}
]

 

4. The body of your email would like:

EmailContent = "<html><body>Test,<p>Lot&nbsp;Bid Status&nbsp;Current High Bid</p><p>$Subscriber.CustomText1 $Subscriber.CustomText2 $Subscriber.CustomText3</p><p>$Subscriber.CustomText4&nbsp;$Subscriber.CustomText5&nbsp;$Subscriber.CustomText6</p><p>$Subscriber.CustomText7$Subscriber.CustomText8&nbsp$Subscriber.CustomText9</p></body></html>",

 

 

Rich Marcucella
Sr. Technical Writer, Content Developer
Web Services Team
http://developer.constantcontact.com
Occasional Advisor

Re: Dynamic Content via C# CTCT Wrapper

I understand that and that's why i would need an array of nested custom_fields without a limitation of fields (currently max 15) because customer can easily have 20+ outbid lots. As I mentioned my example was small and CC custom_fields is just to limited for our use case and the table needing to be displayed has more columns so that's that leaves me with, at most, two or three records to display data. 

 

I appreciate the follow ups as they have confirmed my understanding. I do, however, at least have a better idea of the use cases we can use the custom_fields for in the future.

 

Appreciate your time and expertise!

 

Jose