Utility.CreateNewContact:The given key was not present in the dictionary

Utility.CreateNewContact:The given key was not present in the dictionary


I am getting the above error when using CreateNewContact method. I am using below option with my



ContactOptInList contactOptInList = newContactOptInList();

            contactOptInList.OptInSource =


            contactOptInList.ContactList =

newContactList("Contacts from Contact Form", true);




AuthenticationData authdata = newAuthenticationData();

        authdata.Username =myUserName;

        authdata.Password =myPassword;

        authdata.ApiKey =myAPIKey;





The most likely cause is you aren't setting the OptInSource for the Contact object:


Contact.OptInSource = ContactOptSource.ActionByCustomer;


If you set that, it's like that the error will go away.  Once this error is cleared up though, you will get another error about the Contact List not existing.  When you set the ContactList object, it must contain a valid List Id.  When using new ContactList(String name, Boolean optInDefault) constructor, it doens't set the Id value for that list to a Valid Id.  This will cause a 400 error to be returned from our API.


You'll likely want to either hard code the Id of the list you're setting, if you are always planning on using the same list, or use the getLists() method in the Utility to pull all the lists and allow user selection if there should be selction options.  If you want to hard code the list ID, just pull the XML for your lists to get the ID number of the list you want to use and manually set it in your code.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

View API documentation, code samples, get your API key.

Visit Page