How to Store HTML with styles in Variables

I’m Testing an Email Contents to check whether the email will land on spam or not

The Request is simple:

{
    "message": "{{email_original_content}}",
    "subject": "Subject",
    "recipient": "{{gmail_acc}}"
}

But the problem is i can’t store a large HTML code with styles in it, I’m getting this Syntax Error:

SyntaxError: Unexpected token m in JSON at position 39<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at parse (/snapshot/build/node_modules/body-parser/lib/types/json.js:89:19)<br> &nbsp; &nbsp;at /snapshot/build/node_modules/body-parser/lib/read.

For example if i’m storing this HTML in a variable and send the request i will get the Error above:

const email_original_content = 
`<p>Test</p><p style="margin-top: 24px; font-size: 20px; font-weight: bold;">Deposit instructions</p>`;

But without the style it will successfully send the request:

const email_original_content = 
`<p>Test</p><p>Deposit instructions<p>`;

Is it possible to store it with styles or not? or there’s another way of doing this?

That sounds like its down to the API and what the API will accept.

Ultimately, all you are doing is sending a string.

What status code are you receiving when you send this request?

The error looks like its server side and related to parsing that string when it’s received.

Do you have any links to the API specification?

That should tell you what you are allowed to include in the HTML message body.

Yeah that’s my first guess too it looks like in the server side i just thought it was something with parsing in postman because i noticed that i can’t store a large string with too much spaces or indents.

Status Code is 400 Bad Request

Unfortunately i can’t share the API specs since it’s not public, anyway thanks for the response @michaelderekjones

400 errors are usually client side issues.

HTTP response status codes - HTTP | MDN (mozilla.org)

The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Therefore, its telling you that it doesn’t like what is being sent.

Although I would expect the server response to be a bit more descriptive than that. It looks like it is parsing the message to JSON, and then failing.

It’s failing at the “m” which I’m taking to be the “margin-top” element.

You might want to send an escape character with that string as you have quotes which might be the cause of the parsing error.

const email_original_content = 
"<p>Test</p><p style=\"margin-top: 24px; font-size: 20px; font-weight: bold;\">Deposit instructions</p>";
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.