httpRequest 400 using the API and C Sharp.

Occasional Participant

httpRequest 400 using the API and C Sharp.

 Hello, 


I'm using the following code in a class in order to submit a new contact and add them to a list. I'm getting a 400 error which I understand to be xml problems most of the time. However, I can't seem to figure out how to grab the xml that's being sent. I know that my authentication is working as I can faithfully break that and get a differeny error. 


I've just starting working with this API and we have a client that is being somewhat urgent in getting this up and running.


Any help is appreciated.


 The code bombs out on line 1728 of Utility.cs.


 


using ConstantContactBO;


using ConstantContactUtility;


....


           var ccContact = new Contact();


          ccContact.CustomField1 = Server.HtmlEncode(ddOrgTypes.SelectedValue);


          ccContact.CountryCode = Server.HtmlEncode(ddCountries.SelectedValue);


          ccContact.FirstName = Server.HtmlEncode(txtFirstName.Text);


          ccContact.LastName = Server.HtmlEncode(txtLastName.Text);


          ccContact.EmailAddress = Server.HtmlEncode(txtEmailAddress.Text);


          ccContact.JobTitle = Server.HtmlEncode(txtJobTitle.Text);


 


          ContactOptInList contactOptInList = new ContactOptInList();


          contactOptInList.ContactList = new ContactList("General Interest");


          contactOptInList.ContactList = new ContactList("EmailList");


          ccContact.ContactLists.Add(contactOptInList);


          var ccAuth = new AuthenticationData(CcApiKey, CcUsername, CcPassword);


          Utility.CreateNewContact(ccAuth, ccContact);

2 REPLIES 2
Moderator

PRoblem is the ContactList options you are setting, they must be the ID number value of the lists in question.  Check out this post for how you would want to creat them.  developer.constantcontact.com/node/2033


 


It's also worth mentioning that this should be throwing an exception with a full detailed message of the error.  If you put the Utility.CreateNewContact() method in a try/catch block you will be able to catch the exception and get the full error details. 


 


Hope this helps!

Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

 Thanks!


Looks like I was actually getting a 409 - as the e-mail I was testing with was already there. 


Thanks again.

Developer Portal

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

Visit Page