cancel
Showing results for 
Search instead for 
Did you mean: 
Due to an issue with YouTube, inserting videos in your emails is showing an error. Until they are able to resolve this issue, we recommend using a different video hosting service. We will continue to monitor this outage and update you as we have more information.

Authorization error

Highlighted
Occasional Participant

Authorization error

I am trying to write a script to add email addresses to a mailing list through the API. I have sucessfully authorized the application and gotten both access and refresh tokens, however everytime I try to post the email address with the access token I get a 401 unauthorized error. Posting to 

https://api.cc.email/v3/contacts

Any help would be greatly appreciated. 

5 REPLIES 5
Moderator

Re: Authorization error

Hello @GregC245,

 

Thank you for reaching out to Constant Contact's API Support.

 

Once you have obtained your Access Token you want to send that with your API calls as the Authorization Bearer token.

 

How are you using your the Access Token in your call?


Regards,
Jimmy D.
Tier II API Support Engineer
Occasional Participant

Re: Authorization error

curl_setopt($ch, CURLOPT_URL, $base);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept'=>'application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('authorization'=>'Bearer {'.$access_token.'}'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('cache-control'=>'no-cache'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type'=> 'application/json'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
Moderator

Re: Authorization error

Hello,

 

Thank you for that information. It looks like you are building your authorization header to have braces { } around your access token. These are not needed, so you should build your header like this:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('authorization'=>'Bearer '.$access_token));

Please give that a try and let us know how that works.

 

Regards,
David B.
Tier II API Support Engineer

 

 

Occasional Participant

Re: Authorization error

The API documentation has the braces in the code examples so I wasn't sure. Tried it both ways however with the same result,

 

string(59) "{"error_key":"unauthorized","error_message":"Unauthorized"}"

 

https://v3.developer.constantcontact.com/api_guide/contacts_create.html

Moderator

Re: Authorization error

Hello,

 

What scope are you using in your OAuth authorization flow?


Regards,
David B.
Tier II API Support Engineer