Reply
Occasional Contributor
JasonW70521
Posts: 3
Registered: ‎02-19-2012

Getting 401 Unauthorized on Create an Event with basic auth

[ Edited ]

Hi,

 

I'm a trial customer and I'm trying to create an event using basic authentication.  I am using the same credentials for the POST below as I do for the GET of events (not shown).  The GET works fine for getting the events.  The POST to create an event does not and returns a 401 Unauthorized. 

 

Log of Apache Http Components client:

 

2012-02-24 11:32:19,972 INFO  (ctct.TestBase:31) - Initial Test
2012-02-24 11:32:19,981 DEBUG (ctct.HttpConnector:66) - executing request to: https://api.constantcontact.com/ws/customers/jweden1/events
2012-02-24 11:32:20,070 DEBUG (tsccm.ThreadSafeClientConnManager$1:221) - Get connection: HttpRoute[{s}->https://api.constantcontact.com], timeout = 0
2012-02-24 11:32:20,074 DEBUG (tsccm.ConnPoolByRoute:350) - [HttpRoute[{s}->https://api.constantcontact.com]] total kept alive: 0, total issued: 0, total allocated: 0 out of 20
2012-02-24 11:32:20,074 DEBUG (tsccm.ConnPoolByRoute:523) - No free connections [HttpRoute[{s}->https://api.constantcontact.com]][null]
2012-02-24 11:32:20,075 DEBUG (tsccm.ConnPoolByRoute:369) - Available capacity: 2 out of 2 [HttpRoute[{s}->https://api.constantcontact.com]][null]
2012-02-24 11:32:20,075 DEBUG (tsccm.ConnPoolByRoute:549) - Creating new connection [HttpRoute[{s}->https://api.constantcontact.com]]
2012-02-24 11:32:20,635 DEBUG (conn.DefaultClientConnectionOperator:145) - Connecting to api.constantcontact.com:443
2012-02-24 11:32:20,850 DEBUG (protocol.RequestAddCookies:132) - CookieSpec selected: best-match
2012-02-24 11:32:20,862 DEBUG (protocol.RequestAuthCache:75) - Auth cache not set in the context
2012-02-24 11:32:20,863 DEBUG (client.DefaultRequestDirector:645) - Attempt 1 to execute request
2012-02-24 11:32:20,863 DEBUG (conn.DefaultClientConnection:264) - Sending request: POST /ws/customers/jweden1/events HTTP/1.1
2012-02-24 11:32:20,865 DEBUG (conn.Wire:63) - >> "POST /ws/customers/jweden1/events HTTP/1.1[\r][\n]"
2012-02-24 11:32:20,866 DEBUG (conn.Wire:63) - >> "Accept: application/atom+xml[\r][\n]"
2012-02-24 11:32:20,866 DEBUG (conn.Wire:63) - >> "ContentType: application/atom+xml[\r][\n]"
2012-02-24 11:32:20,866 DEBUG (conn.Wire:63) - >> "Content-Length: 1011[\r][\n]"
2012-02-24 11:32:20,868 DEBUG (conn.Wire:63) - >> "Host: api.constantcontact.com[\r][\n]"
2012-02-24 11:32:20,868 DEBUG (conn.Wire:63) - >> "Connection: Keep-Alive[\r][\n]"
2012-02-24 11:32:20,903 DEBUG (conn.Wire:63) - >> "User-Agent: Apache-HttpClient/4.1.3 (java 1.5)[\r][\n]"
2012-02-24 11:32:20,903 DEBUG (conn.Wire:63) - >> "[\r][\n]"
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:268) - >> POST /ws/customers/jweden1/events HTTP/1.1
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:271) - >> Accept: application/atom+xml
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:271) - >> ContentType: application/atom+xml
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:271) - >> Content-Length: 1011
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:271) - >> Host: api.constantcontact.com
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:271) - >> Connection: Keep-Alive
2012-02-24 11:32:20,904 DEBUG (conn.DefaultClientConnection:271) - >> User-Agent: Apache-HttpClient/4.1.3 (java 1.5)
2012-02-24 11:32:20,905 DEBUG (conn.Wire:63) - >> "?xml version="1.0" encoding="UTF-8" standalone="yes"?[\n]"
2012-02-24 11:32:20,906 DEBUG (conn.Wire:63) - >> "                <atom:entry xmlns:atom="http://www.w3.org/2005/Atom">[\n]"
2012-02-24 11:32:20,906 DEBUG (conn.Wire:63) - >> "                    <atom:content>[\n]"
2012-02-24 11:32:20,906 DEBUG (conn.Wire:63) - >> "                        <Event>[\n]"
2012-02-24 11:32:20,906 DEBUG (conn.Wire:63) - >> "                            <Name>2011 Run For Dimes 5K</Name>[\n]"
2012-02-24 11:32:20,906 DEBUG (conn.Wire:63) - >> "                            <Title>2011 Run For Dimes 5K</Title>[\n]"
2012-02-24 11:32:20,907 DEBUG (conn.Wire:63) - >> "                            <EventType>OUTDOORS_RECREATION</EventType>[\n]"
2012-02-24 11:32:20,907 DEBUG (conn.Wire:63) - >> "                            <StartDate>2013-08-11T09:00:00-04:00</StartDate>[\n]"
2012-02-24 11:32:20,907 DEBUG (conn.Wire:63) - >> "                            <EndDate>2013-09-11T18:00:00-04:00</EndDate>[\n]"
2012-02-24 11:32:20,907 DEBUG (conn.Wire:63) - >> "                [0x9]    <TimeZone>[\n]"
2012-02-24 11:32:20,907 DEBUG (conn.Wire:63) - >> "                [0x9][0x9]<ID>US/Eastern</ID>[\n]"
2012-02-24 11:32:20,907 DEBUG (conn.Wire:63) - >> "                [0x9]    </TimeZone>[\n]"
2012-02-24 11:32:20,908 DEBUG (conn.Wire:63) - >> "                            <EventContact>[\n]"
2012-02-24 11:32:20,908 DEBUG (conn.Wire:63) - >> "                [0x9][0x9]<Name>John Smith</Name>[\n]"
2012-02-24 11:32:20,908 DEBUG (conn.Wire:63) - >> "                [0x9]    </EventContact>[\n]"
2012-02-24 11:32:20,908 DEBUG (conn.Wire:63) - >> "                [0x9]    <EventLocation>[\n]"
2012-02-24 11:32:20,908 DEBUG (conn.Wire:63) - >> "                                <Location>Myer Arena</Location>[\n]"
2012-02-24 11:32:20,909 DEBUG (conn.Wire:63) - >> "                            </EventLocation>[\n]"
2012-02-24 11:32:20,909 DEBUG (conn.Wire:63) - >> "                        </Event>[\n]"
2012-02-24 11:32:20,909 DEBUG (conn.Wire:63) - >> "                    </atom:content>[\n]"
2012-02-24 11:32:20,909 DEBUG (conn.Wire:77) - >> "                </atom:entry>"
2012-02-24 11:32:20,914 DEBUG (conn.Wire:63) - << "HTTP/1.1 401 Unauthorized[\r][\n]"
2012-02-24 11:32:20,917 DEBUG (conn.Wire:63) - << "Connection: close[\r][\n]"
2012-02-24 11:32:20,917 DEBUG (conn.Wire:63) - << "Content-Length: 1145[\r][\n]"
2012-02-24 11:32:20,918 DEBUG (conn.Wire:63) - << "Content-Type: text/html;charset=utf-8[\r][\n]"
2012-02-24 11:32:20,918 DEBUG (conn.Wire:63) - << "Date: Fri, 24 Feb 2012 16:32:20 GMT[\r][\n]"
2012-02-24 11:32:20,918 DEBUG (conn.Wire:63) - << "Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate, no-cache="Set-Cookie"[\r][\n]"
2012-02-24 11:32:20,918 DEBUG (conn.Wire:63) - << "Pragma: no-cache[\r][\n]"
2012-02-24 11:32:20,918 DEBUG (conn.Wire:63) - << "Server: Apache[\r][\n]"
2012-02-24 11:32:20,919 DEBUG (conn.Wire:63) - << "Vary: Accept-Encoding,User-Agent[\r][\n]"
2012-02-24 11:32:20,919 DEBUG (conn.Wire:63) - << "WWW-Authenticate: Basic realm="api.constantcontact.com"[\r][\n]"
2012-02-24 11:32:20,919 DEBUG (conn.Wire:63) - << "X-Powered-By: [\r][\n]"
2012-02-24 11:32:20,919 DEBUG (conn.Wire:63) - << "Set-Cookie: BIGipServerProdAPI=205919242.6695.0000; path=/[\r][\n]"
2012-02-24 11:32:20,919 DEBUG (conn.Wire:63) - << "[\r][\n]"
2012-02-24 11:32:20,920 DEBUG (conn.DefaultClientConnection:249) - Receiving response: HTTP/1.1 401 Unauthorized
2012-02-24 11:32:20,920 DEBUG (conn.DefaultClientConnection:252) - << HTTP/1.1 401 Unauthorized
2012-02-24 11:32:20,921 DEBUG (conn.DefaultClientConnection:255) - << Connection: close
2012-02-24 11:32:20,921 DEBUG (conn.DefaultClientConnection:255) - << Content-Length: 1145
2012-02-24 11:32:20,921 DEBUG (conn.DefaultClientConnection:255) - << Content-Type: text/html;charset=utf-8
2012-02-24 11:32:20,921 DEBUG (conn.DefaultClientConnection:255) - << Date: Fri, 24 Feb 2012 16:32:20 GMT
2012-02-24 11:32:20,921 DEBUG (conn.DefaultClientConnection:255) - << Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate, no-cache="Set-Cookie"
2012-02-24 11:32:20,921 DEBUG (conn.DefaultClientConnection:255) - << Pragma: no-cache
2012-02-24 11:32:20,922 DEBUG (conn.DefaultClientConnection:255) - << Server: Apache
2012-02-24 11:32:20,922 DEBUG (conn.DefaultClientConnection:255) - << Vary: Accept-Encoding,User-Agent
2012-02-24 11:32:20,922 DEBUG (conn.DefaultClientConnection:255) - << WWW-Authenticate: Basic realm="api.constantcontact.com"
2012-02-24 11:32:20,922 DEBUG (conn.DefaultClientConnection:255) - << X-Powered-By:
2012-02-24 11:32:20,922 DEBUG (conn.DefaultClientConnection:255) - << Set-Cookie: BIGipServerProdAPI=205919242.6695.0000; path=/
2012-02-24 11:32:20,935 DEBUG (protocol.ResponseProcessCookies:122) - Cookie accepted: "[version: 0][name: BIGipServerProdAPI][value: 205919242.6695.0000][domain: api.constantcontact.com][path: /][expiry: null]".
2012-02-24 11:32:20,937 DEBUG (client.DefaultRequestDirector:1088) - Target requested authentication
2012-02-24 11:32:20,937 DEBUG (client.AbstractAuthenticationHandler:151) - Authentication schemes in the order of preference: [negotiate, NTLM, Digest, Basic]
2012-02-24 11:32:20,937 DEBUG (client.AbstractAuthenticationHandler:174) - Challenge for negotiate authentication scheme not available
2012-02-24 11:32:20,938 DEBUG (client.AbstractAuthenticationHandler:174) - Challenge for NTLM authentication scheme not available
2012-02-24 11:32:20,938 DEBUG (client.AbstractAuthenticationHandler:174) - Challenge for Digest authentication scheme not available
2012-02-24 11:32:20,938 DEBUG (client.AbstractAuthenticationHandler:161) - Basic authentication scheme selected
2012-02-24 11:32:20,940 DEBUG (client.DefaultRequestDirector:1198) - Authorization challenge processed
2012-02-24 11:32:20,940 DEBUG (client.DefaultRequestDirector:1226) - Authentication scope: BASIC 'api.constantcontact.com'@api.constantcontact.com:443
2012-02-24 11:32:20,941 DEBUG (client.DefaultRequestDirector:1233) - Found credentials
2012-02-24 11:32:20,942 DEBUG (conn.DefaultClientConnection:165) - Connection closed
2012-02-24 11:32:20,942 DEBUG (conn.DefaultClientConnectionOperator:145) - Connecting to api.constantcontact.com:443
2012-02-24 11:32:20,955 DEBUG (protocol.RequestAddCookies:132) - CookieSpec selected: best-match
2012-02-24 11:32:20,955 DEBUG (protocol.RequestAddCookies:184) - Cookie [version: 0][name: BIGipServerProdAPI][value: 205919242.6695.0000][domain: api.constantcontact.com][path: /][expiry: null] match [(secure)api.constantcontact.com:443/ws/customers/jweden1/events]
2012-02-24 11:32:20,956 DEBUG (protocol.RequestAuthCache:75) - Auth cache not set in the context
2012-02-24 11:32:20,961 DEBUG (client.DefaultRequestDirector:619) - Cannot retry non-repeatable request
2012-02-24 11:32:20,962 DEBUG (conn.DefaultClientConnection:152) - Connection shut down
2012-02-24 11:32:20,962 DEBUG (tsccm.ThreadSafeClientConnManager:272) - Released connection is not reusable.
2012-02-24 11:32:20,963 DEBUG (tsccm.ConnPoolByRoute:434) - Releasing connection [HttpRoute[{s}->https://api.constantcontact.com]][null]
2012-02-24 11:32:20,963 DEBUG (tsccm.ConnPoolByRoute:679) - Notifying no-one, there are no waiting threads
2012-02-24 11:32:20,964 DEBUG (tsccm.ThreadSafeClientConnManager:282) - Shutting down

 

[*Note from a CTCT Community Admin: I removed the beginning and ending brackets from the "?xml version="1.0" encoding="UTF-8" standalone="yes"?" line in your post above because that line breaks the "Developer Support" tab in our CTCT "Labs JMML Q&A" Facebook app (apparently, the app is trying to render that line as is, which wouldn't be acceptable in the middle of a page).]

Nick_G
Posts: 162
Kudos: 12
Solutions: 9
Registered: ‎04-20-2011

Re: Getting 401 Unauthorized on Create an Event with basic auth

Hi Jason,

 

Would you be able to run the same query using RESTClient, and if you still experience the 401, save the request as an RCQ file and email that to webservices@constantcontact.com?

 

I'd also be interested to know what language you're using. Thanks!

Nick Galbraith
Support Engineer
Occasional Contributor
JasonW70521
Posts: 3
Registered: ‎02-19-2012

Re: Getting 401 Unauthorized on Create an Event with basic auth

Nice Tool!.  Found the problem in my code as it worked with the tool.  Thanks.

Frequent Visitor
ArtD89
Posts: 1
Registered: ‎04-20-2012

Re: Getting 401 Unauthorized on Create an Event with basic auth

Could you please share the problem?  I am having the same issue, but cannot find a hint as to what is causing the problem.  Thanks in advance.

 

I am using the PHP ConstantContact.php library and the following line of code is generating the subsequent error.

 

$this->_client = new ConstantContact('basic', $api_key, $api_user, $consumer_secret);  

 

 

 

Constant Contact HTTP Request Exception:

HTTP Status 401 - Unable to authenticate user contentshelfdev


type Status report

message Unable to authenticate user contentshelfdev

description This request requires HTTP authentication (Unable to authenticate user contentshelfdev).


Mark-C
Posts: 181
Topics: 3
Kudos: 10
Solutions: 14
Registered: ‎07-23-2011

Re: Getting 401 Unauthorized on Create an Event with basic auth

[ Edited ]

Hello,

 

What type of authentication are you using? The wrapper should be using OAuth by default, and it stores the OAuth credentials in the session. Try closing your session (close browser), then reauthenticate. We also reset our API services this earlier today due to a latency issue, which may also be related. You can also code another means of secure storage on your server/host or possibly use cookies to manage your OAuth crednetials if you are accessing from a single browser so the credentials are preserved between sessions. 

 

Please let us know whether a new session and reauthenticating resolve your issue.

 

Cheers,

Mark Coleman
Support Engineer