I'm trying to create a new campaign via API, here is the relevant code (Python):
########################################################################################################
# Create a campaign with custom html
########################################################################################################
#read in the custom html
with open("HTMLEmailTemplate-Default.txt", "r") as file:
html_content = file.read()
# define the necessary details to create the campaign, note format type=5 is custom coded email
campaignDetails = {
"name":"Test-Campaign1",
"email_campaign_activities":{
"format_type":"5",
"from_name":"test-constantcontact",
"from_email":"test-constantcontact@ablt.ai",
"reply_to_email":"test-constantcontact@ablt.ai",
"subject":"test subject line",
"html_content": html_content
}
}
def createCampaign(access_token,campaignDetails):
url = 'https://api.cc.email/v3/emails'
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
json_data = json.dumps(campaignDetails)
response = requests.post(url, headers=headers, data=json_data)
if response.status_code == 200:
campaign = response.json()
return campaign
else:
print(f"Error: {response.status_code}")
print(response.json())
return None
createCampaign(access_token,campaignDetails)
campaigns=getCampaigns(access_token)
print(campaigns)
I do get a printout of the existing campaigns but the creation of the new on fails with the following error:
Error: 500
[{'error_key': 'http.status.error_unknown', 'error_message': 'Internal Server Error'}]
Which seems to be a problem on the Constant Contact side but I'm not sure what the issue might be, any ideas?
Hello KorashH,
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.
It looks like you are missing the bracket after "email_campaign_activities" and also the "physical_address_in_footer" section from your JSON request body.
Example:
{
"name": "value",
"email_campaign_activities": [
{
"format_type": 5,
"from_name": "value",
"from_email": "value@value.com",
"reply_to_email": "value@value.com",
"subject": "value",
"html_content": "<html><body>value<\/body><\/html>",
"physical_address_in_footer": {
"address_line1": "value",
"address_line2": "value",
"address_line3": "value",
"address_optional": "value",
"city": "value",
"country_code": "value",
"country_name": "value",
"organization_name": "value",
"postal_code": "value",
"state_code": "value",
"state_name": "value",
"state_non_us_name": "value"
}
}
]
}
Create an Email Campaign
https://v3.developer.constantcontact.com/api_guide/email_campaign_create.html
Please have a look and let us know if you have any other questions!
Announcements
Join our list to be notified of new features and updates to our V3 API.
Sign Up