API returning invalid data?

Regular Participant

API returning invalid data?

I have an odd issue using the API. Basically I GET a Contact from the account, which works perfectly fine, but when I try to PUT that Contact back again - without changing anything - I get a HTTP 400 error: "Invalid data: Unknown StateName value".



Not being a US citizen, I can't be entirely sure, but I do believe the validation error is correct as the StateName for this particular Contact is '41':


  <StateCode/>
<StateName>41</StateName>
<CountryCode>us</CountryCode>
<CountryName>United States</CountryName>

I am a bit surprised as I'd expect the data produced by the API to be valid enough for the API to consume, but it doesn't look like that's the case.


How should I cope with this situation? I can't really go around moving the Contact or in any other way modify her data behind her back.

Jakob Skjerning

substancelab.com - crafting quality web applications

 

5 REPLIES 5
Employee

Sorry for the long response time. When you upload a contact and declare the country as US, we doing some validation on the State that is being used, which is why you are seeing the error "Error 400: Invalid data: Unknown StateName value" when using the state name "41". However, if you are uploading contacts in bulk using our activities collection, it will not throw you an error and will actually take this value. This then causes the issue that you are having when performing an update via the Contacts Collection


 


We are looking into our bulk operations, and I will update this thread as soon as I have any updates regarding that. Unfortunately, in the mean time the only two solutions I can offer are:


 


1. Remove the US country code, which would prevent the state validation that is happening.


2. Update the state from "41" to a valid State name.

David J

Regular Participant

I have no idea if this particular data is being used by some other service using your API.


I don't particularily feel comfortable changing the data of users when they haven't asked for it - this seems like a choice and a change you should've made when you decided to invalidate the data you store?


Certainly, the two fixes you propose works well in this one, specific case, but they are hardly something that can be applied in general to all Contacts we try to update. Also, I can't switch to bulk activities as it's against your terms to use those for single transactions.


For now, it seems like we'll have to silently fail - effectively blocking the user from subscribing to any newsletters via our service. Ah well, it's not really that big a deal, just thought I'd let you know about the inconsistency.

Jakob Skjerning

substancelab.com - crafting quality web applications

 

Moderator

Hi Jakob,


 


Thanks for the update.  We are aware of the validation inconsistency through our two import methods.  With the Bulk Import, we do provide warnings for the incorrect data.  We do, however, allow it through.  This type of issue generally doesn't cause problems for sign up forms as the users are generally prompted with a list of available countries and states.   For this reason, those fields generally are only allowed acceptable values that pass validation.


 


If you are allowing customers to update their profiles, they can be prompted to update their State/Country value to select a valid State/Country code.  In the meantime, we are investigating our policy of allowing invalid data through the Bulk Activity API.  Will update if we change anything.

Dave Berard
Senior Product Manager, Constant Contact
Occasional Participant

HI Dave,

I have the same problem except that when i run your API the state and country pulldown menu don't work and a lot of errors (2 for each state and country actually - thats around 500 errors). each state and each country has an error.

When loading any API that has state and country, these errors appear:

 

Notice: Undefined index: state in C:\wamp\www\add_contact.php on line 273

Notice: Undefined index: country in C:\wamp\www\add_contact.php on line 316

 

can you please help me with this? i've been at this for 6 days already.

 

thanks

Hey,

 

It sounds that you may be using our Contact sample forms which are soon do be deprecated.  The errors or notices rather are showing up because it may be trying to use a resource that is not set.  Notices you typically do not need to worry abouty as they show up on a SandBox environment but not so much on a production.  For instance, I see that you are using Wamp which is hosted on your desktop.  By default the settings are showing you ever possible conflict as WAMP is used for a localhost and not so much as a production host.  You can read how to disable the notices here.  Once you change the PHP.ini file the notices will go away and then you should still be able to see Warnings and Errors.  

Ryan Davis
Quality Engineer
Developer Portal

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

Visit Page