How do I pass HTML into a HTTP request API call?

Hey all, currently trying to pass a FreshService API call that contains html inside of the body (To pass tables), I’m unsure if this is possible or the best way to do it. I’ll show what I’m passing through right now, which is giving an invalid json format due to the html.

{
"requester_id": 211000459205,
"description": "<HTML><HEAD><STYLE type=text/css>body {font-family: Calibri;}p {margin: 0;}.mapping {background-color: #D3D4D7;color: black;padding: 'px;}}</STYLE><META content=IE=6 http-equiv=X-UA-Compatible></HEAD><BODY><P style="MARGIN: 0px"><EM>TMW Load Assignment automation&nbsp;completed at </EM><EM>08:30:50</EM><EM>&nbsp;on </EM><EM>Thursday, 04 May 2023</EM><EM>.</EM></P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px">2&nbsp;orders attempted. '&nbsp;require manual input.</P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px">Report file can be found at Y:\Applications\RPA\Developers\Repository\German\TMW_Load_Tester.xlsx</P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px"><FONT size=5>Exceptions</FONT></P><P style="MARGIN: 0px"><TABLE height=''%' cellSpacing=0 cellPadding=8 width=''00%' border='><TBODY><TR><TH width='20%'>RefNum</TH><TH width='20%'>Operation</TH><TH width='20%'>DriverID</TH><TH width='20%'>StartTime</TH><TH width='20%'>Status</TH></TR><TR><TD width='20%'>TestRef3</TD><TD width='20%'>TestOp3</TD><TD width='20%'>TestDriverID3</TD><TD width='20%'>TestStartTime3</TD><TD width='20%'>Failed</TD></TR></TBODY></TABLE></P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px">&nbsp;</P><P style="MARGIN: 0px"><FONT size=5>Successes</FONT></P><P style="MARGIN: 0px"><TABLE height=''%' cellSpacing=0 cellPadding=8 width=''00%' border='><TBODY><TR><TH width='20%'>RefNum</TH><TH width='20%'>Operation</TH><TH width='20%'>DriverID</TH><TH width='20%'>StartTime</TH><TH width=", 
"subject": " TEST - Do Not process (EBOL)", 
"email": "test@yahoo.com", 
"priority":3, 
"status": 2, 
"group_id": 211000155928,
"category": "No additional action needed."
}

Your HTML code is incomplete, it cuts a tag at the end of your line. Wouldn’t it be part of your problem ?

Your code block shows color difference between the first lines and the last lines, which makes it look like there’s something not correct in the way it is built.
By passing it into VSCode I can see errors on your HTML line. The “margin: 0px” quotes are confusing the string you’re passing as the “description” value. Same issue happens on your path line.
I suggest you use escape characters for those. Use \" instead of just " for the margin part and \\ instead of just \ for the path part.

Here’s the clean JSON format :

{
    "requester_id": 211000459205,
    "description": "<HTML><HEAD><STYLE type=text/css>body {font-family: Calibri;}p {margin: 0;}.mapping {background-color: #D3D4D7;color: black;padding: 'px;}}</STYLE><META content=IE=6 http-equiv=X-UA-Compatible></HEAD><BODY><P style=\"MARGIN: 0px\"><EM>TMW Load Assignment automation&nbsp;completed at </EM><EM>08:30:50</EM><EM>&nbsp;on </EM><EM>Thursday, 04 May 2023</EM><EM>.</EM></P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\">2&nbsp;orders attempted. '&nbsp;require manual input.</P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\">Report file can be found at Y:\\Applications\\RPA\\Developers\\Repository\\German\\TMW_Load_Tester.xlsx</P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\"><FONT size=5>Exceptions</FONT></P><P style=\"MARGIN: 0px\"><TABLE height=''%' cellSpacing=0 cellPadding=8 width=''00%' border='><TBODY><TR><TH width='20%'>RefNum</TH><TH width='20%'>Operation</TH><TH width='20%'>DriverID</TH><TH width='20%'>StartTime</TH><TH width='20%'>Status</TH></TR><TR><TD width='20%'>TestRef3</TD><TD width='20%'>TestOp3</TD><TD width='20%'>TestDriverID3</TD><TD width='20%'>TestStartTime3</TD><TD width='20%'>Failed</TD></TR></TBODY></TABLE></P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\">&nbsp;</P><P style=\"MARGIN: 0px\"><FONT size=5>Successes</FONT></P><P style=\"MARGIN: 0px\"><TABLE height=''%' cellSpacing=0 cellPadding=8 width=''00%' border='><TBODY><TR><TH width='20%'>RefNum</TH><TH width='20%'>Operation</TH><TH width='20%'>DriverID</TH><TH width='20%'>StartTime</TH><TH width=", 
    "subject": " TEST - Do Not process (EBOL)", 
    "email": "test@yahoo.com", 
    "priority":3, 
    "status": 2, 
    "group_id": 211000155928,
    "category": "No additional action needed."
    }

As you can see, it didn’t change the color issue. BUT, correcting the HTML incomplete tags issue will correct it, so you better look that out. Looking at it precisely in VSCode I see it was cut at the middle of the line 62.
Looking more closely, there’s something that bothers me but I’m not a HTML expert : Your tags are all in uppercase and in my editor they doesn’t show as working tags. But I’m not an expert so I don’t know about that behavior

So close your HTML code properly with the JSON I supplied you and retry

keep in mind, that attribute values will be surrounded by doublequotes

type=text/css vs type="text/css"

For placing doublequotes within a string we ahve to escape it with another doublequote: like:
"Hello ""New"" World"

As it is about JSON we would also mention that it can be an option to serialize the HTML String and use the result as value e.g. for the description property

keep in mind, that attribute values will be surrounded by doublequotes

This is why I tried to explain how backslashes and quotes require escape characters, so I would hope he would fix that when fixing his HTML content

As it is about JSON we would also mention that it can be an option to serialize the HTML String

I’m not a JSON nor a HTML expert, so I didn’t know about serialization. Could you explain how to do so for both of us ?

Newtonsoft.Json.JsonConvert.SerializeObject("Hello ""New"" World")

Where do you do that ? Inside a UiPath Assign activity ?

Yes e.g. when updating / setting the value of JObject / JSON Property

And what does it output ?

Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

1 Like