I'm trying to use Python and the Constant Contact API to push new contacts to Constant Contact and add them to a list. So far, I have tried the following:
import requests
url = 'https://api.cc.email/v3/contacts'
url_completed = url + '?api_key=' + api_key
post_request = {
"email_address": {
"address": "abc123@gmail.com"
},
"first_name": "First",
"last_name": "Last",
"create_source": "Account",
"list_memberships": ["xxxxxxxxx"]
}
headers = {
'Authorization': 'Bearer xxxxxxx',
'content_type': 'application/json'
}
resp = requests.post(url_completed, data=post_request, headers=headers)
print(resp.raise_for_status())
But when I run this, I get an error 401 Client Error: Unauthorized for url: https://api.cc.email/v3/contacts?api_key=xxxxxxx
Why am I getting this error? For a little more background just to make sure I did this correctly, I went into the Constant Contact dev portal and created a new application. It gave me an API key, which I inserted into the URL, and a Secret, which I assumed was the bearer token, so substituted it in there. I also tested the payload using the Constant Contact reference documentation UI which allows for test payloads after OAuth authentication, and those succeeded. Specifically, I am using this endpoint.
from Using Constant Contact API
No comments:
Post a Comment