Create Campaign get Error json.regex.mismatch

sonp6
Participant

Create Campaign get Error json.regex.mismatch

Hi all, I got php demo source of Constant Contact and try to test it. I created a key and token, then excute createCampaign function. But I got an error notification below. Please help me what wrong here. Thank you.

(I filled "email_content" with only simple text: "Hello world")

 

Array (

            [error_key] => json.regex.mismatch

            [error_message] => #/email_content: Value does not match the required regex pattern: (?i)<html[^>]*>[\S|\s]*<body[^>]*>[\S|\s]*[\S|\s]*$. 

)

16 REPLIES 16
SonP9
Frequent Participant

Hi all,

when I input the mail content with full HTML code (<html><body><h1>hello world</h1></body></html>), the error show again no longer. But another error appear. It said that:

 

[error_key] => http.status.bad_request
[error_message] => Please enter a valid email address.

 

Althought my inputed  email is valid at 'from_addr' and 'reply_to_addr' fields.

 

Hi,

 

That second error you're getting usually indicates that the email address you are trying to associate with your email campaign isn't a verified address in your account.

 

To see verified addresses in your account, and verify more, you can log into your account and go to My Settings>>Verify Addresses.  You can send a verifiication email to yourself there, and click on a link in the email that is sent out to you in order to verify an address.

 

Best Regards,

Shannon W.

API Support Specialist

SonP9
Frequent Participant

Thanks for your help. I'm sorry but I got another notification error again after doing your solution. 

I captured the result page after submit. I also print POST and error. 

Please help me. Thank you so much :)

 

This is my POST:

Array
(
         [name] => AL Campaign 1
         [subject] => AL Newsletter
         [from_name] => AL Admin
         [from_addr] => redacted@email.com
         [text_content] => Hello world
         [email_content] =>
                          <html><body>Hello world</body></html>

         [greeting_string] => Hi all
         [reply_to_addr] => redacted@email.com
         [lists] => Array
         (
                    [0] => 1
         )

         [schedule_time] => 2013-07-14T17:25:56.000Z
         [format] => HTML
)

 

And the error:

[error_key] => http.status.bad_request
[error_message] => Please enter an address

 

Hello,

 

In this case, your JSON for creating an email is correct, but you are missing an important default setting for your account.

 

In Constant Contact we require a phyiscal address to be sent with every email message so that we can comply with US anti-spam laws. there is a default email address that you can set for your Constant Contact account by going to My Settings -> Organization Address -> Edit Address. Until this has been set, your email campaigns are created without a physical address and cannot be scheduled until one has been added.

 

Once you've gone into the Constant Contact account you're working with and added an address, you should be able to make the same request successfully.

 

Sincerely,

Elijah G.

API Support Specialist

Elijah G.
API Support Engineer
SonP9
Frequent Participant

Hi Elijah_G, thanks for your help, but I have not yet solved this problem. I accessed to my account and set a physical address like your instruction. That's all or I need to choice this physical address when I create a campaign ... and how to do it. Please give some instructions.

Thank you so much.

Hello,

 

Once you have set up the organization address on the account that you are using with the API, then that address will be automatically used for all emails that you create. However, you can also specify the address on a per-campaign basis as well. The JSON format for that can be found on this page listed under message_footer.

 

If you are still stuck after setting the organization address on your Constant Contact account and/or setting the address on the campaign, please reply to this post and I will be happy to help!

 

Sincerely,

Elijah G.

API Support Specialist

Elijah G.
API Support Engineer
SonP9
Frequent Participant

Hi mod, thank you for your help. I run the demo code again, and it's successfull. But when I integrate to my website (with the same key/token), it through the error: {"error_key":"json.enumeration.invalid","error_message":"#/message_footer/country: Instance value does not match any enum value. Valid options are:.......}

 

And another problem, at demo code, when I create campaign, it's said: 

{"error_key":"json.invalid.value.no_script_tags","error_message":"#/email_content: Field does not support script content."}

 

Suggest me any solution, please.

Thank you.

SonP9
Frequent Participant

About {"error_key":"json.invalid.value.no_script_tags","error_message":"#/email_content: Field does not support script content."}

 

This is the html code which I used when try creating campaign:

 

<html><body>
<table background="http://theoptimist.com/design/optimist/images/newsletter/bg_content.png" width="100%">
<tr>
<td colspan="2" valign="top" align="center" bgcolor="#ffffff" width="645" height="168" background="http://theoptimist.com/design/optimist/images/newsletter/footer.png" style="text-align:center;">
<p style="color:#fff; font-size:14px; height:35px; text-align:center; display:block; margin-top:12px;">Follow Us On

 

<span style="margin-left:20px; "><a href="#"><img src="http://theoptimist.com/design/optimist/images/newsletter/icon_google.png" width="30" height="30" alt="" border="0" style="display:inline-block; vertical-align:middle; " /></a></span>

</p>
<p style="margin-top:50px; text-align:center; display:block;">You are receiving this email because we love working with you,<br />
if you no longer wish to receive mail from us you can <a href="#" style="color:#000;">unsubscribe here</a></p>
</td>
</tr>
</table></body></html>

 

 

 

In fact, my html code is more complex, but I must debug the error by the way delete step by step suspicious blocks. With the code block above, I confirm that "<SPAN..." block is the cause of error, but I don't know the reason why. Would you please help me review above code, and point out the error code.

 

Thank you so much

Hi,

 

Sorry for the difficulty here.  I was able to verify that our security filters aren't accepting display:inline-block and have forwarded on the difficulty to our engineers so that they can fix the underlying issue (valid CSS getting filtered).

 

In the meantime, if you split up the style into style="display:inline; display:block" it should go through.  Sorry again for the trouble.

 

Best Regards,

Shannon W.

API Support Specialist

SonP9
Frequent Participant

How about the error:

 {"error_key":"json.enumeration.invalid","error_message":"#/message_footer/country: Instance value does not match any enum value. Valid options are:.......}

 

When I run with demo code, it pass. But when I integrate Constant Contact to my website, it through that error.

SonP9
Frequent Participant

When I try to hard code 

$campaign->message_footer->country = 'US';
$campaign->message_footer->state = 'CO';

before I create/update campaign , it don't show those errors any more. But, why it through those errors? I want to set up those information at constant contact account, not at coding.

 

One more error, when I hard code to pass those errors above, the last notification I get is below:

An unexpected error has occurred. Please contact the webmaster.
[{"error_key":"http.status.bad_request","error_message":"Invalid Content."}] in [mysite]/constantcontact/Util/RestClient.php on line 93

 

Thank you.

Hi,

 

For the country and state errors, my guess is you're adding a message footer to the email, whether or not you're adding the physical address including state and country.  If you've saved the physical address in "My Settings" in the account, you don't need to provide the footer at all.  I've commented it out in the example below, which is a complete PHP create campaign example that works for me (whether I comment out the footer info or not).

 

For the invalid content error, I think we'd really need to see the JSON payload you're sending in, or your code (with sensitive details omitted).  Here is my campaign example.

 

<?php

//Campaign create
require 'src/Ctct/autoload.php';

use Ctct\ConstantContact;
use Ctct\Exceptions\CtctException;
use Ctct\Components\EmailMarketing\Campaign;
use Ctct\Components\EmailMarketing\MessageFooter;

$apiKey = "enter your own";
$accessToken = "enter your own";

$cc = new ConstantContact($apiKey);

// message footer may be be required
/*
$messageFooter = new MessageFooter();
$messageFooter->organization_name = "Constant Contact";
$messageFooter->address_line_1 = "1601 Trapelo Rd";
$messageFooter->city = "Waltham";
$messageFooter->country = "US";
$messageFooter->state = "MA";
$messageFooter->postal_code = "02451";
*/

// campaign
$campaign = new Campaign();
$campaign->name = "my campaign 06242013";
$campaign->subject = "my subject";
$campaign->from_name = "John Doe";
$campaign->from_email = "verified_email@example.com";
$campaign->reply_to_email = "verified_email@example.com";
$campaign->text_content = "This is my text";
$campaign->email_content_format = "HTML";
$campaign->email_content = "<html><body>This is my content</body></html>";
$campaign->greeting_string = "Hello";
//$campaign->message_footer = $messageFooter;

// attempt to add the campaign, dumping out the errors from any exceptions thrown
try {
    $response = $cc->addEmailCampaign($accessToken, $campaign);
    print_r($response);
} catch (CtctException $ex) {
    echo '<pre>';
    print_r($ex->getErrors());
    echo '</pre>';
}

?>

 

 

Best Regards,

Shannon W.

API Support Specialist

SonP9
Frequent Participant

When I create a campaign, it's ok. But when I update the campaign, it through that error.

This is my setting:

setting.PNG

 

And this is the error I get:

error.PNG

 

Ah, I want to ask one more question. I have a campaign and have sent to a group contact already. The status of campaign is updated to something... I want to update something to send that campaign to another group, but it said that: "only draft campaign can update...". How to resend a campaign and "Send now" it via API?

 

Thank you and sorry because I  asked you too much

Hi,

 

No problem.  Could I see the code you're using to update a campaign?  You wouldn't be able to update a campaign with the sample code I provided above, since it uses the addEmailCampaign method, which can only be used to create a new campaign.

 

Once an email campaign is scheduled, it goes into scheduled status, briefly into running status, then sent status after the email has been sent.  You cannot edit a campaign in those statuses--the only time you can update a campaign is before it's scheduled, when it is in draft status.  After the email has been sent, you could reschedule it, without editing it, only to new contacts in one of the lists that the email was already sent to.  You would retrieve (get) the campaign, add contacts to the original list, then use the schedule method again.

 

In order to send the email to a new group of contacts (that aren't added to the original list the email was sent to), and in order to edit the campaign, you would really need to re-create the campaign through the API with a new campaign name, or copy the email campaign by logging into the account.  That way you have a new campaign in draft status that can be edited and sent to any list in your account.

 

Best Regards,

Shannon W.

API Support Specialist

SonP9
Frequent Participant

I have gotten some problems with Constant Contact, I think I must add some images about them, they will be helpfull.

 

This is settings at Constant Contact account:

setting.PNG

 

I created a campaign, and then I get that campaign. The result is below:

log.PNG

 

I think it's the reason why when I try to send campaign, the api notified that, country and state must match any enum value .... 

 

How do you think about that?

Please help me.

Thank you.

Hi,

 

We might have an issue with null values, but so far I'm not able to reproduce what you're seeing.  I can get and update a campaign with the .net wrapper, for instance, by running the code below, and I can also use a restclient to GET the campaign, then PUT (update) the same payload I received from the GET request.  I used the same address values in my account as you did when I created the campaign.

 

string apiKey = "enter your own";
string accessToken = "enter your own";
ConstantContact cc = new ConstantContact(apiKey, accessToken);

//Retrieve campaign
EmailCampaign campaign = cc.GetCampaign("1113914320813");//enter campaign id

Console.WriteLine(campaign.ToJSON());
Console.WriteLine("Campaign retrieved");

cc.UpdateCampaign(campaign);//can only update draft campaigns

 

Could I see the code that you're using to update the campaign created in the account?

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

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

Visit Page