I'm using Sitecore 8 and the new Email Experience Manager module. I have configured a newsletter email message with an empty list from the listmanager as recipients.
When subscribing for the newsletter via a selfmade form, I receive an email address and a name. Now I want to make a new contact with this mail and name and add it to the list in my listmanager via code.
Is there any way to call this list via the api and add a contact to it?
in case you have a tracker available and you dont need the update immediately, the following should work (note that the contact is added to the list upon session expiration):
Greetz, Markus
To create a contact, you can use the sample code below, the contact name is usually the domain name plus the username, e.g. domain\username.
After creating the contact, use the following sample code to add the contact to a recipient list.
I have had the exact same issue, i.e. the list manager reports 0 contacts after adding the contact to the recipient list.
I have investigated the issue closer and found that adding a contact to a recipient list actually just sets a field on the contact in the "sitecore_analytics_index" index (assuming you use Mongo/XDB as the underlying storage). Specifically, Sitecore should update the "contact.tags" field on the contact document with the value "ContactLists:{recipientListGuid}". I tried opening the index with Luke to verify that this field was indeed not being set in the index. The index is located in C:\inetpub\wwwroot[Sitename]\Data\indexes\sitecore_analytics_index.
This led me to the conclusion, that you have to save the contact after adding him to the recipient list.
Summing up, the following code works for me:
Note, the above code is used in an update-scenario. In your case, I guess you just have to move this code:
After this:
UPDATE: Actually the above only works if the contact saved is the contact currently tracked by Sitecore Analytics.
Essentially you can follow this example
The changes are then written when the session is abandoned, like so
Follow this link for the source and more information - http://www.sitecore.net/learn/blogs/technical-blogs/getting-to-know-sitecore/posts/2014/09/introducing-contact-facets