Answers.Body: <p>I created a contact custom field with data type "Note" and field type "RichTextEditor" and then ran this API call:</p>
  
  <pre><code>CRM.api3('Contact', 'create', {
    "contact_type": "Individual",
    "id": 180,
    "custom_15": "&lt;p&gt;&lt;strong&gt;foobar&lt;/strong&gt;&lt;/p&gt;"
  });
  </code></pre>
  
  <p>The value was stored as-is, and shows correctly in the UI.</p>
  
  <p><a href="https://github.com/civicrm/civicrm-core/blob/35e93e6ad119df822d538bed2a7d80cb3492d589/CRM/Utils/API/HTMLInputCoder.php#L123-L126" rel="nofollow noreferrer">This part</a> of <code>CRM_Utils_API_HTMLInputCoder</code> should ensure that custom fields of type <code>RichTextEditor</code> are excluded.</p>
  
  <p>One scenario in which this might not work: Let's say you have another API wrapper that renames a parameter from, say, <code>food_preference</code> to <code>custom_22</code>. If the renaming API wrapper runs <em>after</em> <code>CRM_Utils_API_HTMLInputCoder</code> (not sure what the order is there, I'd guess core ones run first), <code>food_preference</code> would already be encoded before it gets to your wrapper.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-28T08:11:49.677Z
Answers.Text: Thanks pfigel! As I read it correctly your answer works from CiviCRM version 5.13.4 and newer. My question was related to CiviCRM 5.4.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-27T17:03:04.537Z
Answers.LastActivityDate: 2019-05-27T17:03:04.537Z
Answers.UserDisplayName: pfigel
Body: <p>I have in my CiviCRM a custom field which is a memo field with a text editor. If I update the contents of this field through the user interface contents is saved correctly as html. E.g. <code>&lt;p&gt;Hello world&lt;/p&gt;</code></p>
  
  <p>However when I use the api (for example through the api explorer) the html gets malformed. Entering the same html results in the following: <code>&amp;gt;&amp;lt;Hello world&amp;gt;/p&amp;lt;</code></p>
  
  <p>How do I update the contents of a custom field which should html code?</p>
  
  <p>Update: I disocvered there is an API Wrapper in place which encodes the html input. This wrapper gets executed for every api call. See <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/API/HTMLInputCoder.php#L147" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/API/HTMLInputCoder.php#L147</a></p>
  
  <p>Thanks,
  Jaap Jansma</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-05-27T15:31:12.633Z
Comments.Text: Aren't custom fields in `getSkipFields`? What kind of API call are you using? Can you give an example?
Comments.UserDisplayName: bgm
Tags: <api><html>
Title: Updating Memo/Rich Text Editor Fields with the API
ThreadText: # Updating Memo/Rich Text Editor Fields with the API
  
  (Asked by: username_0 on 2019-05-27)
  
  I have in my CiviCRM a custom field which is a memo field with a text editor. If I update the contents of this field through the user interface contents is saved correctly as html. E.g. `<p>Hello world</p>`
  
  However when I use the api (for example through the api explorer) the html gets malformed. Entering the same html results in the following: `&gt;&lt;Hello world&gt;/p&lt;`
  
  How do I update the contents of a custom field which should html code?
  
  Update: I disocvered there is an API Wrapper in place which encodes the html input. This wrapper gets executed for every api call. See <https://github.com/civicrm/civicrm-core/blob/master/CRM/Utils/API/HTMLInputCoder.php#L147>
  
  Thanks,
  username_0 Jansma
  
  **Tags:** api, html
  
  > **Comments:**
  > **username_1**: Aren't custom fields in `getSkipFields`? What kind of API call are you using? Can you give an example?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-05-27. Score: 4 | Accepted answer
  
  I created a contact custom field with data type "Note" and field type "RichTextEditor" and then ran this API call:
  
  ```
  CRM.api3('Contact', 'create', {
    "contact_type": "Individual",
    "id": 180,
    "custom_15": "<p><strong>foobar</strong></p>"
  });
  
  ```
  
  The value was stored as-is, and shows correctly in the UI.
  
  [This part](https://github.com/civicrm/civicrm-core/blob/35e93e6ad119df822d538bed2a7d80cb3492d589/CRM/Utils/API/HTMLInputCoder.php#L123-L126) of `CRM_Utils_API_HTMLInputCoder` should ensure that custom fields of type `RichTextEditor` are excluded.
  
  One scenario in which this might not work: Let's say you have another API wrapper that renames a parameter from, say, `food_preference` to `custom_22`. If the renaming API wrapper runs *after* `CRM_Utils_API_HTMLInputCoder` (not sure what the order is there, I'd guess core ones run first), `food_preference` would already be encoded before it gets to your wrapper.
  
  > **Comments:**
  > **username_0**: Thanks username_2! As I read it correctly your answer works from CiviCRM version 5.13.4 and newer. My question was related to CiviCRM 5.4.  
  
  ---
  
  