1 Reply Latest reply on Apr 4, 2017 1:18 PM by gbrettmiller

    Invalid HTML in content text field

    nrajesh

      Hi All,

       

      create discussion via REST API (/api/core/v3/contents) throws error recently like below, before it was working fine.

       

      { "error":{ "message": "Invalid HTML in content text field","status": 400,"code": "contentBodyInvalid" } }

       

      When I analyze the root cause of this issue I found that character '&' is making the problem. I don't know why the API accepts Subject field having '&' but not content.

       

      Example:

      "subject":"[1234567] - [abc & xyz Inc.] - [[abc] abcdefghjk]"

       

      Working:

      Migration KX(~!@#$%^*)

       

      NotWorking:

      Migration KX(~!@#$%^&*)

       

      Request:

      {

           "type":"discussion",

           "question":true,

           "parent":"https:\/\/abc.com\/api\/core\/v3\/places\/543210",

           "subject":"[1234567] - [abc & xyz Inc.] - [[abc] abcdefghjk]",

           "content":{

                "type":"text\/html",

                "text":"<pre\">

                          ID #: <a href=\"https:\/\/abc.com\/case?id=1234567\">1234567<\/a><br>

                          Product1: abc<br>

                          Product2: xys<br>

                          <strong>Question 1?:<\/strong> <br>Migration KX(~!@#$%^&*)<br>

                          <strong>Question 2?:<\/strong> <br>Migration KX<br>

                          <\/pre>"

           }

      }

       

      Can you guys please give some suggestion to fix this.

       

      Regards

      Rajesh

        • Re: Invalid HTML in content text field
          gbrettmiller

          We've run into this problem as well. I think the difference is that the Subject field does not allow / process any type of markup, so it reads the string as-is whereas the Content field will process the contents as html and so will read special characters as those characters and not just a piece of text.  One option that I've used in the past is to use a regular expression to replace the "&" with "and" before posting:

           

          contentText = String(contentText).replace(/[&]/g, "and");

          1 person found this helpful