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
<?php
$first_name = "test";
$last_name = "tester";
$email = "net3431@yahoo.com";
$zipcode = "85308";
/////////// REGISTER EMAIL WITH CONSTANT CONTACT ///////////////////
$UN = "charlottewright";
$PW = "*******";
$Key = "f76*2*46-f*5e-42*c-b5a*-687b*d11*1*f";
...
I have removed the password and obfuscated the key.
Also, I changed RETURNTRANSFER to be zero:
curl_setopt($session, CURLOPT_RETURNTRANSFER, 0); // If you set this to 0, it will take you to a page with the http response
I expected to be able to execute this file and pick up a contact in the target account:
http://www.vestsbycharlotte.com/vest1files/cc.php
PLease help explain what I am missing.
cURL is enabled on this site:
http://www.vestsbycharlotte.com/vest1files/phpinfo.php
I also tried the script on http://onlygooddreams.com/cc.php with a similar lack of results.
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.
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
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
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
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
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!
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 B Support Engineer, Constant Contact
What functionality are you
What functionality are you talking about?
Thx
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 B Support Engineer, Constant Contact
I am having some issues with
I am having some issues with this code as well. I keep getting a Error 401: Error reported: 401
to be sure, the
$UN - this would be constant contact login info?
$PW - this would be the password for the account?
$Key - this would be the api key
i am using this curl code
// Initialize the cURL session
$request ="https://api.constantcontact.com/ws/customers/" . $UN . "/contacts";
$session = curl_init($request);
// Set up digest authentication
$userNamePassword = $Key . '%' . $UN . ':' . $PW ;
// Set cURL options
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
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, 1); // If you set this to 0, it will take you to a page with the http response
thanks
-tom
Might want to try adding this
Might want to try adding this line to your options:
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
James Benson, PHP Developer.
Constant Contact Services: http://integrationservic.es/