bashpostmancode-generationpostman-collection

How to generate code using Postman Collection


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?


Solution

  • 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