Learn from experts and connect with global tech leaders at POST/CON 24. Register by March 26 to save 30%.

Learn more →
X

Using Newman to run collections with file-post requests

Avatar

A lot of people have been asking how to use the collection runner to run collections which have requests with file-uploads. Right now, it’s not possible to upload files in the collection runner. However, you can use Newman, Postman’s command-line companion, as a workaround:

  1. Create a collection in Postman. This collection sends a single POST request, with two form parameters – one file param, and one text param.  The file that was used is https://gist.github.com/abhijitkane/4aba1c3deeb4ed61a623

The request runs successfully in the main Postman window:

Postman run successful
Postman run successful
  1. Export the file as a JSON, and save it to your filesystem.

  2. Open the JSON file for editing. In line 22, change the “value” property of the file param to the complete path of the file:

  1. Run the collection file in Newman:
Collection successfully run in Newman
Collection successfully run in Newman

If you are using Windows, be sure to change the backslashes () in the JSON file to double-backslashes so that the JSON remains valid, e.g. if your “value” is “C:\Documents\collection.json”, you’ll need to change it to “C:\\Documents\\collection.json”.


This tutorial has been updated: https://blog.postman.com/2017/09/21/run-collections-with-file-uploads-using-newman/

Tags:

What do you think about this topic? Tell us in a comment below.

Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

14 thoughts on “Using Newman to run collections with file-post requests

  • Avatar

    How can I do export to JSON in 2nd step?

    • Avatar

      In the main Postman window, in the collection sidebar on the left hand side, hover our cursor over the collection name. You should see a ‘Share collection’ icon.

  • Avatar

    I’m trying to run a collection with a file upload post, however it always returns 404. It works in the chrome app fine. I’m thinking it has to do with not finding the filename?

    • Avatar

      Just did some testing, looks like it’s finding the file, but when I isolated it into a single request in a collection, I get an unexpected end of input error

      • Avatar

        Nevermind, it was all on my end. Love the tool! Thanks

  • Avatar

    I’m trying to run newman with a file upload for different set of files. I’m using “-d” and specifying a json file with the additional filepaths. However, it iterates with only the one file mentioned in the collection.

  • Avatar

    I downloaded Newman in order to be able to download files using the collection runner. However, after trying to run a collection I always receive the following error:

    Iteration 1 of 1
    stream.js:94
    throw er; // Unhandled stream error in pipe.
    ^
    Error: EISDIR, read
    at Error (native)
    spyros@spyros-SZ77:~/npm-global/lib/node_modules/newman/bin$

  • Avatar

    Can I integrate newman with my build server which is Bamboo instead of using Jenkins?

  • Avatar

    I create a collection in Postman and export the file as a JSON. I’m trying to run Newman but the file does not work (It works with Postman). It has this error “ReferenceError in test-script”.
    How to overcome this error?
    Thanks.

  • Avatar

    https://github.com/postmanlabs/newman/issues/525

    Read the last post.

    Tl:dr:
    1. You dont need to set the property enabled
    2. instead of “value” you use “src”

  • Avatar

    How do I give custom name to collection runner report file using newman?
    I tried ,
    newman -c mycollection.json -o outputfile.json
    But the output file name is newman-run-report-2016-10-19-10-26-34-619-0.
    Is it possible to give custom name?

  • Avatar

    I think I’m following everything perfectly, but I keep getting the error:

    *unable to load form file for upload: “undefined” . *

    The records I’m trying to create still get created successfully, they just don’t have the attachment included with them.

    Anyone know what that error message means?

    • Avatar

      I was getting the same warning message (* not an error *) when I ran newman command line scripts exported from postman. I looked into the collection JSON file and for all GET requests, postman inserted unrequired/unneeded “body” element in the “request” block for each GET request that had form-data information (used to upload a file). This was probably leftover from previous testing in postman I was doing at the time. When I removed the entire “body” element from the GET request block, the warning message disappeared. I would inspect the JSON file for any unused “body” element that has “form-data” info in your request blocks and remove them if they were exported w/o really serving any purpose.

    • Avatar

      Hey Josh,
      I was having the same issue and finally this worked:
      {
      “key”: “invoice”,
      “type”: “file”,
      “enabled”: true,
      “src”: “C:\\Documents\\invoice.jpg”
      }
      So I needed to have ‘src’ rather than ‘value’, and needed to add the extension of the file.