0
0
Postmantesting~10 mins

Creating monitors in Postman - Test Execution Walkthrough

Choose your learning style9 modes available
Test Overview

This test creates a Postman monitor to run a collection automatically and verifies the monitor creation success message.

Test Code - PyTest
Postman
import requests

# Set Postman API endpoint and API key
api_key = 'your_postman_api_key'
collection_uid = 'your_collection_uid'
url = 'https://api.getpostman.com/monitors'

# Define monitor creation payload
payload = {
    "monitor": {
        "name": "Daily API Test Monitor",
        "target": {
            "type": "collection",
            "data": {
                "uid": collection_uid
            }
        },
        "environment": null,
        "schedule": {
            "enabled": true,
            "delay": 0,
            "interval": {
                "count": 1,
                "unit": "hour"
            }
        },
        "region": "us-east-1"
    }
}

# Set headers
headers = {
    'X-Api-Key': api_key,
    'Content-Type': 'application/json'
}

# Send POST request to create monitor
response = requests.post(url, json=payload, headers=headers)

# Assert monitor creation success
assert response.status_code == 200, f"Expected status 200 but got {response.status_code}"
json_response = response.json()
assert 'monitor' in json_response, "Response JSON does not contain 'monitor' key"
assert json_response['monitor']['name'] == 'Daily API Test Monitor', "Monitor name mismatch"
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment ready with API key and collection UID configured-PASS
2Sends POST request to Postman API endpoint to create a monitor with specified name and scheduleHTTP POST request sent to https://api.getpostman.com/monitors with JSON payload-PASS
3Receives HTTP response from Postman APIResponse status code and JSON body receivedCheck response status code is 200PASS
4Parses JSON response and verifies 'monitor' key existsJSON response parsedVerify 'monitor' key is present in response JSONPASS
5Verifies the monitor name in response matches the requested nameMonitor details extracted from responseMonitor name equals 'Daily API Test Monitor'PASS
6Test ends successfullyMonitor created and verified-PASS
Failure Scenario
Failing Condition: API key is invalid or missing, or collection UID is incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after sending the POST request?
AThat the monitor runs immediately
BThat the response contains a list of collections
CThat the response status code is 200 and the monitor name matches
DThat the API key is printed in the response
Key Result
Always verify the API response status code and key response fields to confirm that the resource was created successfully.