We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Another 400 error on adding contacts

SteveS83
Occasional Participant

Another 400 error on adding contacts

I am having the 400 error when trying to add a contact with the API. I have scoured these forums and I still am unable to find my problem. Below I have posted my XML that is being sent to the server. Thanks in advance!

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

<title type="text"></title>

<updated>2011-07-12T15:21:40</updated>

<author></author>

<id>data:,none</id>

<summary type="text">Contact</summary>

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

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

<EmailAddress>testb@test.com</EmailAddress>

<FirstName>Tester</FirstName>

<LastName>Admin</LastName>

<OptInSource>ACTION_BY_CUSTOMER</OptInSource>

<ContactLists>

<ContactList id="http://api.constantcontact.com/ws/customers/MYUSERNAME/lists/5"></contactlist>

</ContactLists>

</Contact>

</content>

</entry>

 

4 REPLIES 4
Ryan_D
Employee

Hello,

 

I understand that you hare having some errors when trying to create a new contact using our API.  Take a look at the API documentation to make sure that you are doing a POST to the correct URI. 

 

New Contact Creation (requires POST method)

Adding existing contact to a new list (requires PUT method)

 

If you have any further questions please let me know.

 

Regards,

Ryan Davis
Quality Engineer
SteveS83
Occasional Participant

I checked the method and I am using POST to attempt to add new contacts.

 

Here is some of the php code and the output is below:

public function httpPost($request, $parameter)
{
$postRequest = $this->httpRequest('send', 'POST', $request, $parameter);
return $postRequest;
}
public function createContact($contact)
{
$utility = new Utility();
$call = $utility->getApiPath() . '/ws/customers/'. $utility->getLogin() .'/contacts';
$return = $utility->httpPost($call, $contact);
$code = $return['info']['http_code'];
$test = var_dump($contact) ."<br />".var_dump($call) ."<br />".var_dump($return) ."<br />". $code;
return $test;
}

 And the echoed output:

string(684) "<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>2011-07-13T17:11:57</updated>
<author></author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>Admin@test.com</EmailAddress>
<FirstName>Admin</FirstName>
<LastName>Test</LastName>
<OptInSource>ACTION_BY_CONTACT</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/MYUSERNAME/lists/5"></contactlist>
</ContactLists>
</Contact>
</content>
</entry>"

string(62) "https://api.constantcontact.com/ws/customers/MYUSERNAME/contacts"

array(3) {
["xml"]=>
bool(false)
["info"]=>
array(20) {
["url"]=>
string(62) "https://api.constantcontact.com/ws/customers/MYUSERNAME/contacts"
["content_type"]=>
NULL
["http_code"]=>
int(400)
["header_size"]=>
int(0)
["request_size"]=>
int(1017)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(20)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.14)
["namelookup_time"]=>
float(0)
["connect_time"]=>
float(0.031)
["pretransfer_time"]=>
float(0.093)
["size_upload"]=>
float(684)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(4885)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0.14)
["redirect_time"]=>
float(0)
}

["error"]=>
string(37) "The requested URL returned error: 400"

 

Hello,

 

I just noticed in your XML that you are submitting that there is a small error. 

Spoiler
<entry xmlns="http://www.w3.org/2005/Atom">
    <title type="text"> </title>
    <updated>2011-07-13T17:11:57</updated>
    <author></author>
    <id>data:,none</id>
    <summary type="text">Contact</summary>
    <content type="application/vnd.ctct+xml">
        <Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
            <EmailAddress>Admin@test.com</EmailAddress>
            <FirstName>Admin</FirstName>
            <LastName>Test</LastName>
            <OptInSource>ACTION_BY_CONTACT</OptInSource>
            <ContactLists>
                <ContactList id="http://api.constantcontact.com/ws/customers/MYUSERNAME/lists/5"></contactlist>
            </ContactLists>
        </Contact>
    </content>
</entry>

 Where <ContactList> is being used, you are not ending it correctly.  You can do so by using:

Spoiler

 or

Spoiler

 XML is case sensitive and that is why you hare expericing that 400 error.

 

Please let me know if this works for you.

 

Regards,

Ryan Davis
Quality Engineer
SteveS83
Occasional Participant

Thanks Ryan_D!  Works perfect after changing the XML tag.

Developer Portal

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

Visit Page