Question

Encoded HTML resulting in JSON error

  • 4 October 2023
  • 2 replies
  • 89 views

I’m using an App Extension for Constant Contact to create an email campaign from a Drupal website but I’m having trouble importing HTML for the email because the special characters (like < and >) are being encoded (to < and &gt;) which results in invalid JSON.

TL;DR : Is it possible to use an input field in App Extensions that supports HTML? Currently I can only use Text or String for this field, which I believe is incorrectly encoding my HTML and is resulting in these issues.

------

I have already added transforms to escape characters that would result in JSON errors, but when HTML is placed in the Body of the App Extension, it is being processed as a string and encoded like this:

Original value: <p><a href=\"\">Visit ConstantContact.com!</a>

Encoded value: &lt;p&gt;&lt;a href=\&quot;https://constantcontact.com/\&quot;&gt;Visit ConstantContact.com!&lt;/a&gt;&lt;/p&gt;

These encoded characters are resulting in the error: “Request body contains invalid JSON.” When I test the request via the Constant Contact API manually with the Original value in place, it succeeds. Note: I am using valid to and from emails, just not posting them here. I also am submitting each request with a unique “name” value since that is also a requirement. See below:

 

Successful Request through Constant Contact API test:
https://developer.constantcontact.com/api_reference/index.html#!/Email_Campaigns/createEmailCampaignUsingPOST

{
  "name": "Email Campaign Subject 1",
  "email_campaign_activities": [
    {
      "format_type": 5,
      "from_name": "XXX",
      "from_email": "test@test.org",
      "reply_to_email": "test@test.org",
      "subject": "Email Campaign Subject",
      "preheader": "Preheader",
      "html_content": "<html><body>[[trackingImage]]<p><a href=\"\">Visit ConstantContact.com!</a></p></body></html>”
    }
  ]
}

 

Failed Request though Zapier test:

{
  "name": "Email Campaign Subject 2",
  "email_campaign_activities": [
    {
      "format_type": 5,
      "from_name": "XXX",
      "from_email": "test@test.org",
      "reply_to_email": "test@test.org",
      "subject": "Email Campaign Subject",
      "preheader": "Preheader",
      "html_content": "<html><body>[[trackingImage]]&lt;p&gt;&lt;a href=\&quot;https://constantcontact.com/\&quot;&gt;Visit ConstantContact.com!&lt;/a&gt;&lt;/p&gt;</body></html>”
    }
  ]
}


2 replies

here for the same type of question, sorry I don’t have an answer.
It would be nice if there was a predefined bit of Zapier code or a formatter step that automatically escapes JSON special characters. 
I don’t think there is, so I’m going to play with a lookup/replace process.

@rayogram how did you solve this?

Hi Lorne, I haven't solved it! As far as I can tell there seems to be an internal step in the Constant Contact App Extension that is encoding the HTML characters since they're being saved as “Text” or “String". I think they would have to add an HTML option for the field in order for me to save HTML as a value. So I've moved on to another solution without Zapier for the client but would be curious if this becomes available. 

Reply