The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

HTTP Response Code '403'Received: JBoss Web/2.1.2.GA - Error report

Highlighted
New Member

HTTP Response Code '403'Received: JBoss Web/2.1.2.GA - Error report

$ch = curl_init();

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

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

<updated>2008-07-23T14:21:06.407Z</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>test_100@example.com</EmailAddress>

<OptInSource>ACTION_BY_CUSTOMER</OptInSource>

<ContactLists>

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

</ContactLists>

</Contact>

</content>

</entry>';





$UN = "NIRCH100";

$PW = "NICKCHAIN";

$Key = "blah blah";

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



curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($ch, CURLOPT_USERPWD, $userNamePassword);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS , $theXML);

curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml"));

curl_setopt($ch, CURLOPT_HEADER, false);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_URL, 'https://api.constantcontact.com/ws/customers/username/contacts');

$content = curl_exec($ch);

echo"------------------ ADD CONTACT ------------------";

echo "Connecting to '".str_replace('http://', 'https://', 'http://api.constantcontact.com/ws/customers/NIRCH100/contacts');

echo "And Posting:<pre>\n\n---START---\n". htmlspecialchars($theXML) ."\n---END---\n\n</pre>";

echo "HTTP Response Code '".curl_getinfo($ch, CURLINFO_HTTP_CODE)."'";

echo "Received:<pre>\n\n---START---\n". htmlspecialchars($content) ."\n---END---\n\n</pre><br><br>";

curl_close($ch);


Kindly help me out to find where I am missing as the above code does not add a contact.


The reponse: HTTP Response Code '403'Received:  JBoss Web/2.1.2.GA - Error report

1 REPLY 1
Highlighted
Employee

Error 403

Error 403 typically means that you are trying to access a URI collection that you do not have permission to access. I tested the code that you posted and was able to replicate the error you were receiving. After looking at your code, I noticed the URL you are making the request to is using 'username' in place of your actual username (or the variable you are using to store your username). If you make the modification below, this should resolve your issue.


 


Try changing:


 


curl_setopt($ch, CURLOPT_URL, 'https://api.constantcontact.com/ws/customers/username/contacts');


 


To:


 


curl_setopt($ch, CURLOPT_URL, 'https://api.constantcontact.com/ws/customers/'.$UN.'/contacts');


 


I hope this helps, please let us know if you have any other questions.

David J

Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured