php create new contact code not working for me

Highlighted
Occasional Participant

php create new contact code not working for me

Hi
I created a file cc.php from your basic php example, and I can't get a contact on my target account.
The only lines I changed were the following:

testing constant contact
--
net3431@yahoo.com working for vestsbycharlotte.com
11 REPLIES 11
Highlighted
Participant

Check your contact lists in the XML

Did you set the correct numbers in the XML for your contact lists? The ones in the example are just that -- examples -- yours may be different:

<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/1" />' // Do this for all the lists you want to add to

The list number is at the end of the URI.
Highlighted
Solution Provider

RE: php create new contact code not working for me

I believe you are using the code found here

http://developer.constantcontact.com/node/132


This code adds your contact two lists.
Remove this from the code as you don't have a second list

. '<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/2" />' // Be sure to get the correct list number(s) for your list(s)

Mike C Support Engineer, Constant Contact

Highlighted
Occasional Participant

lists checked. Need PHP 5?

Thanks, I checked and we have one list, listID 1.
I changed the code to reflect this, but the response was the same.
No error code was returned to me, no message was logged into the list.

Does this code require PHP 5?
We are running PHP Version 4.3.11

The readme I just downloaded says "first make
sure that you have php5 enabled within your web server".
Do you have an API that works for PHP 4x?
--
net3431@yahoo.com working for vestsbycharlotte.com
Highlighted
Occasional Participant

still does not work. PHP 5 Necessary?

OK, I made the change, tried it, and no results. I don't even get an error message.

I checked for syntax:
No syntax errors detected in cc.php

I took a look at my list, and it looks like it's a listID 1:
...&action=list&listId=1&srchwithinlst=true

Here's the change to the code:

$entry = '<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>' . date('c') . '</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>' . $email . '</EmailAddress>
<FirstName>' . $first_name . '</FirstName>
<LastName>' . $last_name . '</LastName>
<PostalCode>' . $zipcode . '</PostalCode>
<OptInSource>ACTION_BY_CUSTOMER</OptInSource>
<ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/' . $UN . '/lists/1" /></ContactLists>
</Contact>
</content>
</entry>';

It's not putting the contact into any of the lists, awaiting confirmation, nothing anywhere that I can find. I ran it from two different servers.

I would at least expect some response from cURL:

// Set cURL options
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS , $entry);
curl_setopt($session, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));
curl_setopt($session, CURLOPT_HEADER, false); // Do not return headers
curl_setopt($session, CURLOPT_RETURNTRANSFER, 0); // If you set this to 0, it will take you to a page with the http response

// Execute cURL session and close it
$response = curl_exec($session);
curl_close($session);


Does this code require PHP 5?
We are running PHP Version 4.3.11

The readme I just downloaded says "first make
sure that you have php5 enabled within your web server".
Do you have an API that works for PHP 4x?
--
net3431@yahoo.com working for vestsbycharlotte.com
Highlighted
Solution Provider

RE: lists checked. Need PHP 5?

I ran the script that I believe you are using that I found here using php 4.3.11 and it did not work

I then switched to PHP version 5.2.6 and the code works.

The following line of code requires PHP 5
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);

I was able to add a contact using PHP Example for SiteVistorAPI which you can find here

While there is no reason that the APIs themselves won't work from PHP v4, we do not have a PHP v4 compatible sample at this time.

Mike C Support Engineer, Constant Contact

Highlighted
Participant

Is there a line of code that is a PHP 4 equivalent?

I have been working on these forms for a while and I think that this is the problem i am running into. The servers I am using have 4.4.4 and 4.4.8 respectively for PHP. Anyway, any help on this would be great! Thanks all!
Highlighted
Moderator

We currently do not have a

We currently do not have a working PhP 4 sample, php 4 does not support the curl_XXX functionality for this code to work correctly. This functionality was introduced in PhP 5.
Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

What functionality are you

What functionality are you talking about?

Thx
Highlighted
Moderator

Sorry Stefan, I was

Sorry Stefan,

I was referring to the curl_setopt() function which takes care of the entire authentication process and HTTP request process for you. In order to use PHP 4.0 you would have to write the code that does that yourself or use a PHP library created for 4.0. We are not planning on creating any 4.0 examples as PHP no longer supports or updates 4.0 and they are preparing to release 6.0 in the near future.
Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured