The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

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

Highlighted
Occasional Contributor

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

Hi,

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

 

 

ContactOptInList contactOptInList = newContactOptInList();

            contactOptInList.OptInSource =

ContactOptSource.ActionByCustomer;

            contactOptInList.ContactList =

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

 

 

   

AuthenticationData authdata = newAuthenticationData();

        authdata.Username =myUserName;

        authdata.Password =myPassword;

        authdata.ApiKey =myAPIKey;

 

 

 

1 REPLY 1
Highlighted
Moderator

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

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

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured