Export Collection

Very VERY new to this.

I have setup four methods in a Postman collection. The first POST gets a Token (the other three use the Token), the second POST uploads a file somewhere, a GET determines if the file is already there and if so, returns a physicalFileName, a DELETE gets passed the physicalFileName and that file is then deleted.

They all work great … however:

  1. I have to copy/paste the token gotten by the first POST into the Authentication for the 2nd POST, the GET, and the DELETE. I need to pass it from one to the other.

  2. I have to copy/paste the physicalFileAddress returned in the GET into the DELETE.

  3. I need to get this all working in a single script that is external to Postman and can be executed from the file system.

#3 is the biggest concern. If I cannot export my Postman methods to an external script for execution independently from Postman, this is all for nothing.

Thanks in advance for any insight.

Hey @planetoneautomation. First of all, welcome to the community. :smile:

For your first two points, you can easily achieve that by chaining requests using environment variables. You can read more about this here.

Further reading in case you want to dig deeper.

To summarise, you’d be extracting the token from the initial request and setting it as an environment variable.

Environment variables are available throughout the collection run, so you’d be able to simply get the token you had set in the previous request and use it in the subsequent ones.

For #3, I am not really sure what the requirement is, could you clarify what you mean by a “script external to Postman” and what the use case is?

Thank you. I will look into chaining requests with environment variables.

Let me try to make #3 requirement clear …

I need a single self-contained script in the file system with the requests strung together and passing the token and other information as described. I need it to be executable in the file system. It should be standalone - that is, not running in Postman and not dependent on Postman.

For example, to do Windows shell commands, you can create a batch file that does things like changing directories and copying or deleting files, etc. I need a script file (vbs? javascript? cscript? html?) that can be executed in the file system (double-click) and executes the requests as described.

I came across Postman and used it to test that the API I’m using works - it does. It’s been a long long time since I did any web development and did very little way back then so Postman with it’s GUI made it easy for me to get requests working.

I’ve looked and looked for complete examples of using HTTP requests in script files (like html files) but I mostly find snippets of code and don’t know how to put them together. I see the “Code” link in Postman and have copied and pasted the code into files and tried to use them but they don’t execute.

I hope this clarifies. And thank you again.

OK, so I got the environment setup and the variables defined and implemented. I can now run each one without having to copy/paste the Token or the PhysicalFileName. Great.

However, when I open Collection Runner and execute, the POST request that uploads a file fails. When I look at the details, it looks like it fails to use the “file” I have defined in Body with type “file” where I click “Select Files” button and choose a file in the local file system.

So I added an environment variable “file” and set it’s value with full path and filename. I then used {{file}} rather than selecting with “Select Files” button. But this fails with a 500 error.

Any ideas?

Hey @planetoneautomation.

For your #3 requirement, you can look at the Postman collection SDK which allows you to work with collections programmatically.

You could also use the Code functionality you mentioned above, but since that works with individual requests only, you’ll have to generate and combine the code for individual requests. Note: since the code takes care of only request sending, you’ll have to recreate the value persisting logic by parsing responses and setting them as global variables. Or something like async.waterfall, if you’re familiar with it.

For the last part, unfortunately, the runner does not support persisting file paths as of now. This is a known issue that we are working on, and you can track the progress here.