I'm creating an automation where I want to send a link in an e-mail. The e-mail is sent using a curl-able API.
Here is smallest part of the HTML I want to send and reproduces the problem:
printf -v email_body "Click here: \e]8;;file://1.2.3.4/backup/backup.txt\e\Backup.txt\e]8;;\e\\"
When I display it in the terminal, it works perfectly: screenshot of result
When I try to send it, it fails as it says Input must be a valid JSON object
:
curl --request POST \
--url https://api.brevo.com/v3/smtp/email \
--header 'accept: application/json' \
--header 'api-key: xxxxxxxxx' \
--header 'content-type: application/json' \
--data "${email_header}${email_body}${email_footer}"
Everything else is working fine - email_header and email_footer make it a proper JSON/HTML string - i.e. if I remove email_body or put a simple string in it, it works perfectly.
When I save the email_body
I can see with notepad++ that there are escape characters (which is expected):
screenshot of special characters
I tried to escape the special characters like this:
printf -v email_body "Click here: \\e]8;;file://1.2.3.4/backup/backup.txt\\e\\Backup.txt\\e]8;;\\e\\\\"
Still not proper JSON.
What am I missing?
printf 'Text before, \e]8;;%s\e\\%s\e]8;;\e\\\, text after.\n' file://$PWD/myfile.txt "My file here."
, see stackoverflow.com/a/72297683/1765658email_body='"Click here: \u001b]8;;file://1.2.3.4/backup/backup.txt\u001b\\Backup.txt\u001b]8;;\u001b\\"'
Input must be a valid JSON object