I believe this is very basic, but I can't figure out the issue. I have a list called "Test". I get an error when I do the following code in C#
<code>Utility.IsValidUserAuthentication(ad); string[] emailAddress = new string[] {"test@gmail.com"}; string nextChunkId; IList<ConstantContactBO.Contact> list = Utility.SearchContactByEmail(ad, emailAddress, out nextChunkId); if (list.Count == 0) { ConstantContactBO.Contact contact = new ConstantContactBO.Contact("test@gmail.com", "Sal", "Smith"); ConstantContactBO.ContactOptInList cl = new ConstantContactBO.ContactOptInList(); cl.OptInSource = ConstantContactBO.ContactOptSource.ActionByContact; cl.ContactList = new ConstantContactBO.ContactList("Test"); contact.ContactLists.Add(cl); Utility.CreateNewContact(ad, contact); } else { Console.Write("Sal is already there"); }</code>
I get this error:
System.Collections.Generic.KeyNotFoundException: The given key was not present i
n the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at ConstantContactUtility.Components.ContactComponent.CreateAtomEntry(Contact
contact, String accountContactListUri)
at ConstantContactUtility.Utility.CreateNewContact(AuthenticationData authent
icationData, Contact contact)
at ConstantContactSyncPOC1.Program.Main(String[] args)
My authentication is fine - what do I have wrong? I have tried several different ways of refering to the list, but can't figure out what the ID is (used its sort order, but that gave same error).
Thanks!
Sorry for the long response time, this post fell under the radar and I certainly apologize for that.
I just needed to modify the Contact List to use an actual list id (ie: 1, 2, 18 ..etc). You can obtain the list Id by performing an http get on https://api.constantcontact.com/ws/customers/{user-name}/lists, and it will be referred to in the <id> node. I also needed to make a slight modification to the syntax that selects the contact Opt In Source.
I hope this helps resolve your issue. I certainly apologize for any inconvenience this cuased. Please let me know if you have any other questions or concerns regarding this. Thank you.
David J
Thanks! That worked.
With regards to the http get - what do I enter for username / password? I tried retrieving that manually usering regular account credentials, and it did not work (invalid access)
Hello,
The credentials you would use for all API calls would be the following:
Username: {apikey}%{ConstantContactusername}
Password: {ConstantContactPassword}
Andrew T
Support Engineer, Constant Contact