Bird
Raised Fist0
Postmantesting~15 mins

Creating collections in Postman - Automation Script Walkthrough

Choose your learning style10 modes available
Create a new collection in Postman
Preconditions (2)
Step 1: Click on the 'New' button in the top left corner
Step 2: Select 'Collection' from the options
Step 3: Enter 'My API Tests' as the collection name
Step 4: Add a description 'Collection for API testing exercises'
Step 5: Click the 'Create' button
✅ Expected Result: A new collection named 'My API Tests' is created and visible in the Collections sidebar with the correct description
Automation Requirements - Postman API with Newman
Assertions Needed:
Verify the collection is created with the correct name
Verify the collection description matches the input
Best Practices:
Use Postman API to create collections programmatically
Validate response status codes and response body
Use environment variables for authentication tokens
Clean up created collections after test to avoid clutter
Automated Solution
Postman
import requests
import json

# Set your Postman API key here
API_KEY = 'YOUR_POSTMAN_API_KEY'

# Postman API endpoint for collections
url = 'https://api.getpostman.com/collections'

# Headers with API key
headers = {
    'X-Api-Key': API_KEY,
    'Content-Type': 'application/json'
}

# Collection data to create
collection_data = {
    "collection": {
        "info": {
            "name": "My API Tests",
            "description": "Collection for API testing exercises",
            "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
        },
        "item": []
    }
}

# Send POST request to create collection
response = requests.post(url, headers=headers, data=json.dumps(collection_data))

# Assert response status code is 200 (success)
assert response.status_code == 200, f"Expected status 200 but got {response.status_code}"

# Parse response JSON
response_json = response.json()

# Assert collection name and description in response
created_collection = response_json.get('collection', {})
assert created_collection.get('info', {}).get('name') == 'My API Tests', "Collection name mismatch"
assert created_collection.get('info', {}).get('description') == 'Collection for API testing exercises', "Collection description mismatch"

print('Collection created successfully with correct name and description.')

This script uses the Postman API to create a new collection programmatically.

First, it sets the API key for authentication in the headers.

The collection data includes the name and description as required.

It sends a POST request to the Postman collections endpoint.

After receiving the response, it checks the status code to ensure the request succeeded.

Then it verifies the collection name and description in the response match what was sent.

This confirms the collection was created correctly.

Using the API avoids manual UI steps and allows automation.

Common Mistakes - 3 Pitfalls
Hardcoding API key directly in the script without using environment variables
Not checking the response status code before parsing the response body
Ignoring cleanup of created collections after tests
Bonus Challenge

Now add data-driven testing to create three different collections with different names and descriptions

Show Hint

Practice

(1/5)
1. What is the main purpose of creating a collection in Postman?
easy
A. To group API requests for better organization
B. To write code in Postman
C. To change the API server settings
D. To create user accounts

Solution

  1. Step 1: Understand what collections do

    Collections in Postman are used to group API requests together.
  2. Step 2: Identify the main benefit

    This grouping helps organize requests and makes testing easier.
  3. Final Answer:

    To group API requests for better organization -> Option A
  4. Quick Check:

    Collections = Group API requests [OK]
Hint: Collections group requests to keep tests organized [OK]
Common Mistakes:
  • Thinking collections are for coding
  • Confusing collections with server settings
  • Assuming collections create user accounts
2. Which of the following is the correct way to create a new collection in Postman?
easy
A. Go to settings and change the environment
B. Right-click on a request and select 'Delete'
C. Click the 'New' button and select 'Collection'
D. Open the console and type 'create collection'

Solution

  1. Step 1: Locate how to create collections

    In Postman, you create collections by clicking the 'New' button.
  2. Step 2: Select the correct option

    After clicking 'New', you choose 'Collection' to create one.
  3. Final Answer:

    Click the 'New' button and select 'Collection' -> Option C
  4. Quick Check:

    Create collection = New button > Collection [OK]
Hint: Use 'New' button to start creating collections [OK]
Common Mistakes:
  • Trying to delete requests to create collections
  • Changing environment instead of creating collections
  • Typing commands in console to create collections
3. Consider this scenario: You create a collection named 'User APIs' and add three requests to it. What will you see in the Postman sidebar?
medium
A. A folder named 'User APIs' containing the three requests
B. Three separate collections named after each request
C. Only one request visible without any collection
D. An error message about duplicate requests

Solution

  1. Step 1: Understand collection structure

    A collection acts like a folder holding multiple requests.
  2. Step 2: Visualize sidebar display

    The sidebar shows the collection name with its requests nested inside.
  3. Final Answer:

    A folder named 'User APIs' containing the three requests -> Option A
  4. Quick Check:

    Collection = Folder with requests inside [OK]
Hint: Collections appear as folders with requests inside [OK]
Common Mistakes:
  • Thinking each request becomes its own collection
  • Expecting requests to appear without collections
  • Assuming errors occur when adding multiple requests
4. You tried to add a request to a collection but it did not appear inside. What is the most likely mistake?
medium
A. You created a new collection instead of adding to existing one
B. You forgot to save the request after adding it to the collection
C. You closed Postman before adding the request
D. You changed the environment instead of adding the request

Solution

  1. Step 1: Check the process of adding requests

    After adding a request to a collection, you must save it to confirm.
  2. Step 2: Identify common user error

    Forgetting to save means the request won't appear in the collection.
  3. Final Answer:

    You forgot to save the request after adding it to the collection -> Option B
  4. Quick Check:

    Save request after adding = request appears [OK]
Hint: Always save requests after adding to collections [OK]
Common Mistakes:
  • Assuming creating new collection adds request automatically
  • Closing app before saving changes
  • Mixing environment changes with request additions
5. You want to share a set of API tests with your team using Postman collections. Which steps should you follow to create and share the collection properly?
hard
A. Export environment variables only without collections
B. Create individual requests without collections and email each request
C. Change the workspace settings to public without creating collections
D. Create a collection, add requests, save it, then use the 'Share' option to send a link

Solution

  1. Step 1: Create and organize requests in a collection

    First, create a collection and add all relevant API requests to it.
  2. Step 2: Save the collection and use sharing features

    Save the collection and then use Postman's 'Share' option to generate a link or invite team members.
  3. Final Answer:

    Create a collection, add requests, save it, then use the 'Share' option to send a link -> Option D
  4. Quick Check:

    Share collections by saving and using Share link [OK]
Hint: Save collections and use Share link to share with team [OK]
Common Mistakes:
  • Sharing requests individually instead of collections
  • Only exporting environment variables
  • Changing workspace without creating collections
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard