3

I'm aware it is possible to generate code snippets from individual Postman requests, but I can't find similar functionality for a entire collection.
I also know that there are tools like newman for running an exported collection in Postman Collection 2.1 json format.

But specifically what I'm looking for is a tool that generates bash code from a collection or from a exported collection in Postman Collection 2.1 json format. This way my co-workers who don't use Postman can replicate the API requests.

Is this option available in Postman and I'm just missing it or are there any tools that do this?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Arash Outadi
  • 446
  • 7
  • 16

2 Answers2

4

I ended using the Postman SDK and postman-code-gen to create code snippets from Postman Collections that I exported from Postman.

Not really sure why this feature isn't provided already by Postman, but I made a simple CLI tool that does it: https://github.com/arashout/postman-collection-gen

# cURL request generation
node main.js -c example_collection.json

# curl --location --request GET 'https://v7rr12wbr7.execute-api.us-west-2.amazonaws.com/prod/courses?c0=PHYS153&c1=APSC160&c2=CHEM154&version_key=1.2'
# curl --location --request GET 'https://v7rr12wbr7.execute-api.us-west-2.amazonaws.com/prod/courses?c0=PHYS153'


# How to generate other languages:
node main.js -c example_collection.json -l shell,httpie
node main.js -c example_collection.json -l Swift,URLSession
Arash Outadi
  • 446
  • 7
  • 16
  • 2
    thanks!, it needs postman-collection to be installed: npm install postman-collection --save – devwebcl Jan 16 '21 at 15:50
  • The postman code generation is just http client "raw" request and "raw" response. No dto/classes at all. That's why there is no tool/plugin for this. – Cherry Jun 01 '22 at 17:52
2

I'm not sure I understand your question completely. But I can tell you how I export collection and then run tests.

  1. Export Collection to JSON: choose tab 'Collections' at the left tab of the Postman. Select the 3-dot menu and choose 'Export'.
  2. Export your test environment: Open 'Manage Environments'. Click download.
  3. I don't know a tool that generates bash code, I write it manually.

Write .sh file like the following to run your tests.

"newman run your_test_collection.json -r cli -e your_test_environment.json --reporter-cli-no-assertions --global-var"

Usually, I create different .sh files for different sets of tests.

  • No this isn't exactly what I want. My main use case is sharing `curl` snippets from my Collection of requests instead of having team members download `newman` or `Postman` – Arash Outadi Mar 07 '20 at 09:20