API Help: POST (Create) a New Email Campaign
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?
1 reply