7 Replies Latest reply on Feb 15, 2018 7:43 PM by Sanford Whiteman

    Creating File: File is mandatory

    Jerry Toledo

      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

      With the following header:

       

      I'm getting "File is mandatory".

      Is there something else I'm missing?

        • Re: Creating File: File is mandatory
          Sanford Whiteman

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

           

          https://nation.marketo.com/servlet/JiveServlet/downloadImage/2-180385-192444/pastedImage_2.png

            • Re: Creating File: File is mandatory
              Jerry Toledo

              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")
              
                • Re: Creating File: File is mandatory
                  Sanford Whiteman

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

                    • Re: Creating File: File is mandatory
                      Jerry Toledo

                      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

                        • Re: Creating File: File is mandatory
                          Sanford Whiteman

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

                           

                          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--
                          
                          1 of 1 people found this helpful