SOLVED

Replace Email body w/ {id}/fullContent.json POST endpoint

Go to solution
ggerla
Level 2

Replace Email body w/ {id}/fullContent.json POST endpoint

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--"
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Replace Email body w/ {id}/fullContent.json POST endpoint

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:

 

2021-03-07 01_22_44-RFC 2046 - Multipurpose Internet Mail Extensions (MIME) Part Two_ Media Types.png

 

But Marketo's MIME parser is (lightly) broken, considering any extra whitespace to be part of the boundary itself instead of ignoring it.

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

Re: Replace Email body w/ {id}/fullContent.json POST endpoint


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.

ggerla
Level 2

Re: Replace Email body w/ {id}/fullContent.json POST endpoint

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--"
SanfordWhiteman
Level 10 - Community Moderator

Re: Replace Email body w/ {id}/fullContent.json POST endpoint

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:

 

2021-03-07 01_22_44-RFC 2046 - Multipurpose Internet Mail Extensions (MIME) Part Two_ Media Types.png

 

But Marketo's MIME parser is (lightly) broken, considering any extra whitespace to be part of the boundary itself instead of ignoring it.

View solution in original post

ggerla
Level 2

Re: Replace Email body w/ {id}/fullContent.json POST endpoint

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

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Replace Email body w/ {id}/fullContent.json POST endpoint

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):

2021-03-08 12_33_20-Solved_ Re_ Replace Email body w_ {id&#125;_fullContent.json PO... - Marketing Nation.png