How to send HTML Email Data to Xano?

Options
I have HTML email data created by a drag-and-drop email editor and stored in a text variable to send to Xano/Sendgrid. I tried to post the HTML as a JSON field which obviously doesn't work because HTML has similar delimiters like " in the code. So, I wonder what is the best way to convert the HTML email data so that I can send it in the post request to Xano?

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     you would use the Set Header function (under Utility Functions) to set your Content-type: text/html
    [CleanShot 2022-08-18 at 10.11.24.png]
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    It depends on exactly what you are trying to do and from what context, but if you make an HTML string, and then encode that string in JSON, you'll be able to have the info come over as a JSON payload. So if using JS, I would 

    (assuming variable html is a string in scope)
    const obj = {}
    obj.html = html
    obj.hello="hi"
    const json = JSON.stringify(obj);

    const response = await fetch("https://my-xano-instance.xano.com/path-to-endpoint", { method: "POST" body: json }); 
    const resultObj = await response.json()

    and then resultObj is whatever Xano sent back! 
  • Oliver Burrell
    Options
    Thanks very much  ! I wondered if JSON.stringify could  convert html as well, but wasn't sure. I'll try it out ...
  • Oliver Burrell
    Options
    Yes, that worked nicely! Thanks