Create Contact Issue

Highlighted
Occasional Contributor

Create Contact Issue

Hello,

 

I am trying to create a new contact using http://integrationservic.es/ code  1.7.2. I am using the code

 

$contact_list = 0;
 $extra_fields = array(
        'FirstName' => 'Firstname',
        'LastName' => 'Lastname',
    );

$email ="test@example.com";
$cc = new cc('username', 'pwd');

$new_id = $cc->create_contact($email, $contact_list,$extra_fields);
     echo($new_id);

 

No contact is added to the default list. Can you please help?

4 REPLIES 4
Highlighted
CTCT Employee

Re: Create Contact Issue

Hi AnupriyaS,

 

What kind of error are you recieving when your trying to use that code?

 

Regards,

Ryan Davis
Quality Engineer
Highlighted
Occasional Contributor

Re: Create Contact Issue

I am not getting any kind of errors when this code is executed. The response body is blnak.

Tags (1)
Highlighted
Occasional Contributor

Re: Create Contact Issue

I am now trying it directly. But getting a 404 error. Can you please help?

          

            $userNamePassword = $Key . '%' . $UN . ':' . $PW ;

            $entry = '<entry xmlns="http://www.w3.org/2005/Atom">
            <id>http://api.constantcontact.com/ws/customers/'.$UN.'/contacts/'.$SubID.'</id>
            <title type="text">Contact: '.$email.'</title>
            <updated>2008-04-25T19:29:06.096Z</updated>
            <author><name>Admin</name></author>
            <content type="application/vnd.ctct+xml">
            <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/'.$UN.'/contacts/'.$SubID.'">
            <EmailAddress>'.$email.'</EmailAddress>
            <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
            <ContactLists>
            </ContactLists>
            </Contact>
            </content>
            </entry>';

           $tmpfile = tmpfile();
           fwrite($tmpfile, $entry);
           fseek($tmpfile, 0);

           // Initialize the curl session
           $request ="https://api.constantcontact.com/ws/customers/".$UN."/contacts/".$SubID;
   
           $session = curl_init($request);

           // Set up Digest authentication. Put your API key, and CTCT username/pwd here
           $userNamePassword = $Key . '%' . $UN . ':' . $PW ;

           curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
           curl_setopt($session, CURLOPT_USERPWD, $userNamePassword);
           curl_setopt($session, CURLOPT_INFILE, $tmpfile);
           fclose($tmpfile); // Close temp file because it no longer needed

           curl_setopt($session, CURLOPT_PUT, 1);
           curl_setopt($session, CURLOPT_INFILESIZE, strlen($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);
           curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
           $response = curl_exec($session);
           $httpcode = curl_getinfo($session, CURLINFO_HTTP_CODE);
           curl_close($session);

             echo("httpcode error is ".$httpcode);
             if ($httpcode > 199 && $httpcode < 300){
                 return 'Success';
             }else{
                 return 'False';
            }

Highlighted
CTCT Employee

Re: Create Contact Issue

Hi AnupriyaS,

 

I notied that you have resolved your issue on another post on the baords.  Are you still having any issues creating a new contact?

 

Thanks,

Ryan Davis
Quality Engineer
Developer Portal

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

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