The requested URL returned error: 400

sbotezatu
Regular Participant

The requested URL returned error: 400

Hello,

I am new to ConstantContact and new to PHP so please bear with me.


I am trying to set up the sample "add_contact_simple"

I'm getting a "The requested URL returned error: 400 "

I have read over some for the post reguarding this issue and have not had any luck correction the problem.


Thank you very much for your time!




These are the settings in cc_class.php =======================================

     // FROM HERE YOU MAY MODIFY YOUR CREDENTIALS       

        var $login = 'banfisupport';

        var $password = '***************';

        var $apikey = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx';

       

        // CONTACT LIST OPTIONS

        var $contact_lists = array('List Name Here');

        var $force_lists = true;

        var $show_contact_lists = false;

               

        // FORM OPT IN SOURCE -

        var $actionBy = 'ACTION_BY_CONTACT';


       

        // DEBUGGING

        var $curl_debug = true;


 


and this is the file which is suppose to do the job ===============================


include_once('cc_class.php');




$ccContactOBJ = new CC_Contact();

$ccListOBJ = new CC_List();


$emailField=$_POST;


if ($emailField) {

 

 

 //var $result;

 

  $postFields = array();

  $postFields = $emailField;

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "4";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "";

  $postFields = "List Name Here";

  

  $contactXML = $ccContactOBJ->createContactXML(null,$postFields);

  

  echo "$contactXML;";


  if (!$ccContactOBJ->addSubscriberBV($contactXML)) {

   $error = true;

  } else {

   $error = false;

  }

 

  

if (isset($error)) {

  

  if ($error === true) {

   $class = "error";

   $message = $ccContactOBJ->lastError;

  } else {

   $class = "success";

   $message = "Contact ".htmlspecialchars($postFields, ENT_QUOTES, 'UTF-8')." Added.";

  }


  echo '<div class="'.$class.'">';

  echo $message;

  echo '</div>';

 }


 

} else {


 

 $result = 0;

}




 

9 REPLIES 9
DaveBerard
Moderator

The problem looks to be your list name:


 


var $contact_lists = array('List Name Here');

 


That is supposed to be updated to reflect the name of the list in your account you want the contacts added to.  If that hasn't been updated, the form will correctly return a 400 error (unless you have a list named 'List Name Here' in your account).

Dave Berard
Senior Product Manager, Constant Contact
sbotezatu
Regular Participant

Thank you for your quick reply , 'List Name Here' was changed by me... I was initially the real list name. Sorin


 

DaveBerard
Moderator

Sorry for the confusion there, was the most obvious possible problem from the code snippet shown. 


 


400 errors are content related, would it be possible for you to email your xml (found in $contactXML) to our webservices support team so we can look at the exact content that is being generated? 

Dave Berard
Senior Product Manager, Constant Contact
David_J
Employee

I know this had been mentioned above, but I just want to be clear that the following would fail:


$postFields = "http://api.constantcontact.com/ws/customers/{username}/lists/{list-id}";

as the createContactXML() function is expecting an array here. However, placing it in an array such as this would work fine:


$postFields = array("http://api.constantcontact.com/ws/customers/{username}/lists/{list-id}");

If this isn't your issue, please send over your XML to the address Dave B linked above and we'll be glad to take a look at this.

David J

sbotezatu
Regular Participant

I sent the xml text file over as you suggested. I am also put it here because I need all the help I can get. I am pressured to get this to work. May be somebody has similar issues.


Please take a look at the Contact element. Looks that is not terminated!


<?xml version="1.0" encoding="UTF-8"?>

<entry xmlns="http://www.w3.org/2005/Atom">

 <title>TitleNode</title>

 <updated>2011-02-15T10:41:26+01:00</updated>

 <author><name>CTCT Samples</name></author>

 <id>urn:uuid:E8553C09F4xcvxCCC53F481214230867087</id>

 <summary type="text">Customer document</summary>

 <content type="application/vnd.ctct+xml">

  <Contact xmlns="http://ws.constantcontact.com/ns/1.0/">Customer Document

   <EmailAddress>sorin@asitcon.com</EmailAddress>

   <FirstName>Sorin</FirstName>

   <LastName>Botezatu</LastName>

   <MiddleName></MiddleName>

   <CompanyName></CompanyName>

   <JobTitle></JobTitle>

   <OptInSource>ACTION_BY_CONTACT</OptInSource>

   <HomePhone>5166956864</HomePhone>

   <WorkPhone></WorkPhone>

   <Addr1>28-25 35th</Addr1>

   <Addr2></Addr2>

   <Addr3></Addr3>

   <City>Astoria</City>

   <StateCode>NY</StateCode>

   <StateName>New York</StateName>

   <CountryCode>US</CountryCode>

   <PostalCode>11103</PostalCode>

   <SubPostalCode></SubPostalCode>

   <Note></Note>

   <EmailType></EmailType>

   <ContactLists>

    <ContactList id="http://api.constantcontact.com/ws/customers/banfisupport/lists/68"/>

   </ContactLists>

  </Contact>

 </content>

</entry>

David_J
Employee

I was able to successfully post a contact in my account with the XML that you showed us. The only reason I can see why this would work for me and not for you is if you do not have a list id '68' in your account. While looking through your account I did not see a list corresponding to this id in your account, but it is possible I had missed one. I can however verify that your XML here is correct.

David J

sbotezatu
Regular Participant

Hi David,


Thank you very much for your time.


The ListID was wrong. I change that to the right number(58) and It worked. I have no ideea how I missed it.


Thank you again!


Sorin


 

Hi David

 

 

I am facing the same issue. While adding contact using the APIs, it works some time and give 400 error other times. I have checked the XML generated and it seems to be fine too. I am adding teh XML code below for refrence.

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<title>TitleNode</title>
<updated>2013-04-04T02:17:47+01:00</updated>
<author><name>CTCT Samples</name></author>
<id>urn:uuid:E8553C09F4xcvxCCC53F481214230867087</id>
<summary type="text">Customer document</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">Customer document
<EmailAddress>prabhjotsggdfg@yahoo.com</EmailAddress>
<FirstName>Prabhjot</FirstName>
<LastName>Singh</LastName>
<MiddleName></MiddleName>
<CompanyName>SCG</CompanyName>
<OptInSource>ACTION_BY_CONTACT</OptInSource>
<HomePhone>jhgj</HomePhone>
<WorkPhone>01146027229</WorkPhone>
<Addr1>D14/38, First Floor, Sector-7</Addr1>
<Addr2>Rohini</Addr2>
<Addr3>PENDING</Addr3>
<City>Delhi</City>
<StateCode>AB</StateCode>
<StateName></StateName>
<CountryCode>dz</CountryCode>
<PostalCode>110085</PostalCode>
<SubPostalCode></SubPostalCode>
<Note></Note>
<EmailType>HTML</EmailType>
<CustomField1></CustomField1>
<CustomField2></CustomField2>
<CustomField3></CustomField3>
<CustomField4></CustomField4>
<CustomField5></CustomField5>
<CustomField6></CustomField6>
<CustomField7></CustomField7>
<CustomField8></CustomField8>
<CustomField9></CustomField9>
<CustomField10></CustomField10>
<CustomField11></CustomField11>
<CustomField12></CustomField12>
<CustomField13></CustomField13>
<CustomField14></CustomField14>
<CustomField15></CustomField15>
<ContactLists><ContactList id="http://api.constantcontact.com/ws/customers/AWCCMarketing/lists/2"/></ContactLists>
</Contact>
</content>
</entry>

 

The Contact Lists are being retrived using API $ccListOBJ->getLists(); function and list id 2 exists in our account.

 

The config credentials we are using are as follows:

 

var $login = 'AWCCMarketing'; //Username for your account
var $password = 'XXXXXXXX'; //Password for your account
var $apikey = 'Correct-API-Entered-Here'; // API Key for your account.

 

I tried once with entring limited information (Email, First Name, Last Name) and it did not worked, then I entered all infomation with other state and it worked. Then again tried with above information but it gives 400 error. Could you please help. 

 

 

Hi,

 

The error you get in the 400 "State and country codes don't match" means our system wasn't able to validate the state code for the country you gave, which was the country code for Algeria, DZ.  Right now, we don't have full support for state code validations for countries outside of the US.  If you leave the state code value blank for now, the request should go through.

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page