SOLVED

Re: Creating File: File is mandatory

Go to solution
Anonymous
Not applicable

Creating File: File is mandatory

Hello,

I'm following the documentation for creating Files in the Asset database from here: http://developers.marketo.com/rest-api/assets/files/#create_and_update

So I'm using a images and files folder, and trying to create a new file (it currently has no files).

I copy and pasted the body given by the documentation under Create

pastedImage_0.png

With the following header:

pastedImage_1.png

I'm getting "File is mandatory".

Is there something else I'm missing?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Creating File: File is mandatory

You'd highlight that code as Plain (as MIME isn't a supported syntax) like so:

pastedImage_2.png

Which turns it into:

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="file"; filename="marketo.html"

Content-Type: text/html

<html>

<body>

<h1>Test Page - marketo.html</h1>

</body>

</html>

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="name"

marketo.html

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="folder"

{"id":436,"type":"Folder"}

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="description"

This is a test file

------WebKitFormBoundary2VyWOacQSupl4gUL—

The #set() syntax is literal Velocity/Java code. It's not part of using the hightlighter.

Now we can look at the payload properly and see there are several things wrong with it.

First, this boundary is incorrect for your payload (this is exactly why a monospace font is used for code):

multipart/form-data; boundary=------WebKitFormBoundary2VyWOacQSupl4gUL

You have 6 hyphens:

------WebKit...

And your actual MIME parts also have 6 hyphens, which is incorrect:

------WebKit...

In the body, you want 8 hyphens, the constant prefix of -- followed by the boundary.

Second, after the final boundary, you need to have an additional suffix -- (you have an em-dash there instead).

Third, you need to have a line break (CRLF) after the header section of each MIME part.

So the correct format is:

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="file"; filename="marketo.html"

Content-Type: text/html

<html>

<body>

<h1>Test Page - marketo.html</h1>

</body>

</html>

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="name"

marketo.html

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="folder"

{ "id":1187, "type":"Folder" }

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="description"

This is a test file

--------WebKitFormBoundary2VyWOacQSupl4gUL--

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Creating File: File is mandatory

Can you please paste actual code using the Advanced Editor's syntax highlighter?  Troubleshooting a screenshot is really... suboptimal. 

pastedImage_2.png

Anonymous
Not applicable

Re: Creating File: File is mandatory

Which parts of the code?  They're all directly copy and pasted from the examples in the market documentation. The body is from the body provided under the create and update section of the document. I haven't written any code myself, aside from the header

#set($this = "multipart/form-data; boundary=------WebKitFormBoundary2VyWOacQSupl4gUL")

SanfordWhiteman
Level 10 - Community Moderator

Re: Creating File: File is mandatory

All the code. If I want to reproduce your problem I can't copy the screenshot.

Anonymous
Not applicable

Re: Creating File: File is mandatory

Here's the request body:

#set($this = "

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="file"; filename="marketo.html"

Content-Type: text/html

<html>

<body>

<h1>Test Page - marketo.html</h1>

</body>

</html>

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="name"

marketo.html

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="folder"

{"id":436,"type":"Folder"}

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="description"

This is a test file

------WebKitFormBoundary2VyWOacQSupl4gUL—

")

Sent to the endpoint /rest/asset/v1/files.json

SanfordWhiteman
Level 10 - Community Moderator

Re: Creating File: File is mandatory

You'd highlight that code as Plain (as MIME isn't a supported syntax) like so:

pastedImage_2.png

Which turns it into:

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="file"; filename="marketo.html"

Content-Type: text/html

<html>

<body>

<h1>Test Page - marketo.html</h1>

</body>

</html>

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="name"

marketo.html

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="folder"

{"id":436,"type":"Folder"}

------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="description"

This is a test file

------WebKitFormBoundary2VyWOacQSupl4gUL—

The #set() syntax is literal Velocity/Java code. It's not part of using the hightlighter.

Now we can look at the payload properly and see there are several things wrong with it.

First, this boundary is incorrect for your payload (this is exactly why a monospace font is used for code):

multipart/form-data; boundary=------WebKitFormBoundary2VyWOacQSupl4gUL

You have 6 hyphens:

------WebKit...

And your actual MIME parts also have 6 hyphens, which is incorrect:

------WebKit...

In the body, you want 8 hyphens, the constant prefix of -- followed by the boundary.

Second, after the final boundary, you need to have an additional suffix -- (you have an em-dash there instead).

Third, you need to have a line break (CRLF) after the header section of each MIME part.

So the correct format is:

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="file"; filename="marketo.html"

Content-Type: text/html

<html>

<body>

<h1>Test Page - marketo.html</h1>

</body>

</html>

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="name"

marketo.html

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="folder"

{ "id":1187, "type":"Folder" }

--------WebKitFormBoundary2VyWOacQSupl4gUL

Content-Disposition: form-data; name="description"

This is a test file

--------WebKitFormBoundary2VyWOacQSupl4gUL--

Anonymous
Not applicable

Re: Creating File: File is mandatory

This worked, many thanks!

SanfordWhiteman
Level 10 - Community Moderator

Re: Creating File: File is mandatory

Cool, hopefully others will find this thread instead of copying the code examples from the docs.    I assume maybe an editor (not an coder) stripped out the all-important line breaks to save space and didn't know hyphens are special...

Shruti_Khullar
Level 1

Re: Creating File: File is mandatory

Hi Jerry,

I am still facing the same issue. Could you please share the snippet of the code.

Thanks,

Shruti

SanfordWhiteman
Level 10 - Community Moderator

Re: Creating File: File is mandatory

See my correct answer for a proper payload.