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

Programmatically access contact_data API using Python3

MKTG_Team
Rookie
0 Votes

Am trying to access the below API to get access token but am getting error mentioned below the code snippet:

from requests.auth import HTTPBasicAuth
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session

auth_token_url = "https://authz.constantcontact.com/oauth2/default/v1/token"

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
basic_auth = HTTPBasicAuth(client_id, client_secret)
token = oauth.fetch_token(token_url=auth_token_url, auth=basic_auth)

What am i missing here? I need to get access token to make api call to below url:

 

 

Is there a way to generate access token that doesn't expire as am trying to build a data pipeline using this API call. 

 

Error:

UnauthorizedClientError: (unauthorized_client) The client is not authorized to use the provided grant type. Configured grant types: [authorization_code, implicit, refresh_token].

1 REPLY 1
John__B
Moderator
0 Votes

Hello MKTG_Team,

 

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.

 

After reviewing the logs for your keys, I found that the grant_type value being used in your token requests is “client_credentials”. If you are trying to use the authorization code flow, the required grant_type is “authorization_code”.

 

Our access tokens expire after 1440 minutes (86,400 seconds) but your application can utilize refresh tokens to extend the lifespan of an access token by exchanging it for a new set of access and refresh tokens. For more information on this process I am including overview documentation for our OAuth2 authentication and the Authorization Code flow below.

 

OAuth2 Overview:

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

 

Authorization Code Flow:

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

 

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.
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

Polls
How confident are you about the effectiveness of your current marketing strategy?

Top Choice: Not confident at all (76%)