Hello there,
I'm struggling to try to update an email body with the POST {id}/fullContent.json endpoint.
I'm using what is written here: https://developers.marketo.com/rest-api/assets/emails/#replace_html and https://developers.marketo.com/rest-api/endpoint-reference/asset-endpoint-reference/#!/Emails/create...; but there is a little misleading process: what I have to use? A classic text/html boundary text in the POST body, or a JSON encoded parameter? I've tried many different possibilities (like the following example, or the JSON parameter, and so on), but every time, the endpoint returns "content cannot be null" error.
Where I'm doing wrong?
For example, I've something like that, where XXX is my mail ID - I will avoid all the other parameters:
CURLOPT_URL => 'https://063-XUP-724.mktorest.com/rest/asset/v1/email/XXX/fullContent.json',
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
'Content-Type: multipart/form-data; boundary=----Boundaryda7e32be5795ea0',
'Content-length: 498',
'Authorization: bearer YYYY'
),
CURLOPT_POSTFIELDS => "----Boundaryda7e32be5795ea0 Content-Disposition: form-data; name="content"; filename="email_content.html"
Content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <div style="font: 14px tahoma; width: 100%" class="mktEditable" id="edit_text_3">Hello there!</div> </body> </html>
----Boundaryda7e32be5795ea0--"
Solved! Go to Solution.
Looks like you still have extra whitespace (namely at the end of the boundary line).
The payload should look like this:
----Boundaryda7e32be5795ea0
Content-Disposition: form-data; name="content"; filename="email_content.html"
Content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <div style="font: 14px tahoma; width: 100%" class="mktEditable" id="edit_text_3">Hello there!</div></body></html>
----Boundaryda7e32be5795ea0--
Note per the MIME RFC, you should be allowed to have extraneous whitespace after the boundary:
But Marketo's MIME parser is (lightly) broken, considering any extra whitespace to be part of the boundary itself instead of ignoring it.
A classic text/html boundary text in the POST body, or a JSON encoded parameter?
It's a multipart/form-data POST with a single text/html part.
In your example, there's no line break between the boundary sequence and the Content-Disposition. The Content-Disposition header should be on its own line.
Sorry, my fault with the copy-paste operation.
CURLOPT_URL => 'https://063-XUP-724.mktorest.com/rest/asset/v1/email/XXX/fullContent.json',
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array(
'Content-Type: multipart/form-data; boundary=----Boundaryda7e32be5795ea0',
'Content-length: 498',
'Authorization: bearer YYYY'
),
CURLOPT_POSTFIELDS => "----Boundaryda7e32be5795ea0
Content-Disposition: form-data; name="content"; filename="email_content.html"
Content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <div style="font: 14px tahoma; width: 100%" class="mktEditable" id="edit_text_3">Hello there!</div> </body> </html>
----Boundaryda7e32be5795ea0--"
Looks like you still have extra whitespace (namely at the end of the boundary line).
The payload should look like this:
----Boundaryda7e32be5795ea0
Content-Disposition: form-data; name="content"; filename="email_content.html"
Content-type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <div style="font: 14px tahoma; width: 100%" class="mktEditable" id="edit_text_3">Hello there!</div></body></html>
----Boundaryda7e32be5795ea0--
Note per the MIME RFC, you should be allowed to have extraneous whitespace after the boundary:
But Marketo's MIME parser is (lightly) broken, considering any extra whitespace to be part of the boundary itself instead of ignoring it.
Hi Sanford,
sorry, but the problem was with the boundary name! I've added twice the dashes in the boundary name headers.
I've fixed it, so now it works (the RFC was very helpful!)
Thanks,
Gianluca
Yes, I fixed that while testing 🙂 but you also have an extra space after the boundary, unless that's another artifact of copying and pasting (which is confusing):