Got a 'How do I' question? Join our live 'Ask a Trainer' session happening now for instant help and pro tips!

{"error_key":"unauthorized","error_message":"Unauthorized"}bool(true) Issue.

AfshinY
Campaign Collaborator
0 Votes

Hello, I want to add a contact with cURL but I am getting this error;

Error Result:

{"error_key":"unauthorized","error_message":"Unauthorized"}bool(true) Issue.

 

My Code:


  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept'=>'application/json'));
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('authorization'=>'Bearer {XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX}'));
  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);

  $data = array(
  '{
    "email_address": {"address": "danipper@example.com","permission_to_send": "implicit"},
    "first_name": "David",
    "last_name": "Nipper",
    "job_title": "Musician",
    "company_name": "Acme Corp.",
    "create_source": "Account",
    "birthday_month": 11,
    "birthday_day": 24,
    "anniversary": "2006-11-15",
    "steet_addresses":{
      "kind":"home",
      "street": "123 Kashmir Valley Road",
      "city": "Chicago",
      "state": "Illinois",
      "country": "United States",
    }
  }');

  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  //for debug only!
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  $resp = curl_exec($ch);
  curl_close($ch);
  var_dump($resp);
13 REPLIES 13
AfshinY
Campaign Collaborator
0 Votes

no help?

Courtney_E
Moderator
0 Votes

Hello AfshinY,

 

Thank you for reaching out to Constant Contact API Developer Support.

Inquiries made to Constant Contact API Developer Support via email at webservices@constantcontact.com, or via our Developer Community, are answered in the order that they are received, and turnaround times may vary depending on volume. Typically we will be able to respond to requests within 1 to 5 business days.

 

Please have a look and let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Courtney_E
Moderator
0 Votes

Hello AfshinY,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

The response code and example request that you provided indicate that the Access Token value being used is invalid. 

 

V3 API Response Codes - 401: Unauthorized

https://v3.developer.constantcontact.com/api_guide/glossary_responses.html#401-unauthorized

 

The Bearer token value in your Authorization request header must contain a valid Access Token. In order to successfully send requests, you will need to obtain an Access Token by completing authorization via OAuth 2.0 to authenticate a connection between your key/application and your Constant Contact account.

 

Please take a look at our OAuth2 Overview Page to select which flow will best meet your application’s needs:

OAuth2 Overview
https://v3.developer.constantcontact.com/api_guide/auth_overview.html#select-the-oauth2-flow-to-use

 

Please have a look and let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
AfshinY
Campaign Collaborator
0 Votes

hello, thank you for your reply. Yes, I got an access from the applications section, but the unauthorized warning still appears.

AfshinY
Campaign Collaborator

Your instructions are really complex and lacking in details. I've integrated with many APIs before and I think it took 10 minutes at most. but I can't find anything in your instructions that makes this clear. Could you please give me a direct link with the steps, I'm at the end of my patience, thank you.

You're not alone here. I am providing tokens that have "account owner" permissions and every single one of their scopes and I am still getting "Request forbidden due to insufficient authorization scopes. Request forbidden due to insufficient user privileges."

AfshinY
Campaign Collaborator
0 Votes

I don't understand why they distribute an api to an app they don't respond to. Same problem even when I try with Postman It gives me Client_ID and asks me to authorize. When I try to authorize, the authorization page does not come, the tokien does not come, I cannot access it because I cannot get a tokien. It's really hard not to go crazy.

John__B
Moderator
0 Votes

Hello JenniferS1215,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

I noticed that you also reached out to us directly via email and we have followed up with you through that channel. Since you had some additional questions, we’ll continue our communication via email. 

 

Regards,


John B.
API Support Specialist
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
John__B
Moderator
0 Votes

Hello AfshinY,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

The My Applications page on developer.constantcontact.com will only provide the API key and client secret for your application. The OAuth 2.0 authentication system must be used in order to obtain access and refresh tokens. Our OAuth 2.0 system offers 3 different types of authorization flows depending on your application’s requirements. 

 

OAuth 2.0 Authorization Code Flow:

https://developer.constantcontact.com/api_guide/server_flow.html

 

OAuth 2.0 PKCE Flow:

https://developer.constantcontact.com/api_guide/pkce_flow.html

 

OAuth 2.0 Implicit Flow:

https://developer.constantcontact.com/api_guide/client_flow.html

 

If you could provide us with some more information about the type of application you’re looking to integrate, we would be happy to answer any questions you may have about the appropriate authorization flow it can use to successfully make contact addition requests.

 

Please have a look and let us know if you have any other questions!

 

Regards,


John B.
API Support Specialist
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
AfshinY
Campaign Collaborator
0 Votes

There is a popup on the website and I only have an input for a mail. Only the person will write the e-mail and add an e-mail here to be informed about the campaigns. Mail will register in a list called apple list that I created under my Contact. It's just such a simple process, I only get api Key. I have an application, but it gives errors in other steps, unauthorized etc....

Creative_Portland
Rookie
0 Votes

I would agree, the instructions for any of the dev tutorials in regard to API aren't useful or helpful. It is sad and I can imagine a team spent a lot of time writing something that isn't used and will never be appreciated. 

AfshinY
Campaign Collaborator
0 Votes

no help?

Courtney_E
Moderator
0 Votes

Hello AfshinY,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

Inquiries made to Constant Contact API Developer Support via email at webservices@constantcontact.com, or via our Developer Community, are answered in the order that they are received, and turnaround times may vary depending on volume. Typically we will be able to respond to requests within 1 to 5 business days.

 

Currently, if developing your own form using Constant Contact’s API, the only authentication available is OAuth 2.0 and the three flow options listed in the reply from John__B above. 

 

If you are not wanting to go through the process of setting up OAuth 2.0 authentication to connect your website form, we also offer several pre-built form options that can be easily created and installed on your website:

 

Constant Contact offers a variety of pre-built hard-coded sign-up forms that are easy to create and install that will allow you to add website-signups directly from your website into your Constant Contact account:

 

Create a pop-up contact sign-up form for your website

http://knowledgebase.constantcontact.com/articles/KnowledgeBase/21407-Create-a-Pop-up-Sign-Up-Form

 

Create an inline contact sign-up form to embed on a website

http://knowledgebase.constantcontact.com/articles/KnowledgeBase/18265-Create-a-Sign-Up-Form-with-the...

 

Activate and install an inline or pop-up contact sign-up form on a website

http://knowledgebase.constantcontact.com/articles/KnowledgeBase/18053-activating-and-installing-your...

 

Create a Lead Generation Landing Page for capturing new sign-ups

https://knowledgebase.constantcontact.com/articles/KnowledgeBase/32012-Create-a-Lead-Generation-Land...

 

For help with settings or forms within the Constant Contact Website UI, please reach out to our Support Team at 866-289-2101.


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up