Encoding HTML to pass through "customHtml" item in API call

I am reading in content in markdown, convert to HTML, then need to pass that into a Mautic segment email. I set up an API call to create a new segment/list email. It seems to work although not 100% correctly.

If I pass the full-email HTML through the “customHtml” item in the JSON to Mautic, the request fails, presumably because of the “quotes”. If I encode the HTML, it works and builds the HTML correctly in Mautic.

So my question is: How do I encode this HTML programmatically?

EP

Your software
My Mautic version is: 4.1.2
My PHP version is: 7.4.30
My Database type and version is: Mysql 8.0.30