Skip to content

Instantly share code, notes, and snippets.

@LegolasVzla
Last active May 3, 2020 01:38
Show Gist options
  • Save LegolasVzla/819b098d5673a4782ef62d25d7116ead to your computer and use it in GitHub Desktop.
Save LegolasVzla/819b098d5673a4782ef62d25d7116ead to your computer and use it in GitHub Desktop.
List all your postman endpoints with a pretty and clean format
import json
#import pprint
import os
'''
Assuming that you exported your postman collection in your current path
or you can delete os.getcwd() and put the full path of your postman
collection exported file
'''
current_path=os.getcwd()
postman_filename = '<your_postman_collection_filename>.json'
postman_file_path=current_path + '/' + postman_filename
endpoint_list=[]
data = {"collection_name":"","endpoint":"","alias":"","method":""}
with open(postman_file_path) as postman_filename:
postman_file = json.load(postman_filename)
# Iterate on each postman collection
for i,elem in enumerate(postman_file['item']):
# Iterate on each endpoint of the current collection
for j,endpoint in enumerate(elem["item"]):
data = {"collection_name":"","endpoint":"","alias":"","method":""}
data["collection_name"]=elem["name"]
data["endpoint"]=endpoint["name"]
try:
data["alias"]=endpoint["request"]["url"]["raw"]
data["method"]=endpoint["request"]["method"]
except Exception as e:
pass
endpoint_list.append(data)
#pp = pprint.PrettyPrinter(indent=4)
#pp.pprint(endpoint_list)
# Generate your final json file
with open("postman_file_resulting.json","w") as postman_filename:
postman_filename.write(json.dumps(endpoint_list))
'''Output example:
[
{
"collection_name": "Users",
"endpoint": "Create",
"alias": "{{dev}}/api/v1/users"
},
{
"collection_name": "Users",
"endpoint": "Recovery password",
"alias": "{{dev}}/api/v1/users/recovery_password"
}
]
You could use this gist for different purposes, like create assignments for your team according of your endpoint list, for example to create Checklists in Trello.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment