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
Highlighted
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
Highlighted
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);
Highlighted
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

 

 

Highlighted
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

Highlighted
Moderator

Re: Authorization error

Hello,

 

What scope are you using in your OAuth authorization flow?


Regards,
David B.
Tier II API Support 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