Monitor scheduling in Postman - Build an Automation Script
import requests import time import json # Constants API_KEY = 'YOUR_POSTMAN_API_KEY' WORKSPACE_ID = 'YOUR_WORKSPACE_ID' COLLECTION_ID = 'YOUR_COLLECTION_ID' headers = { 'X-Api-Key': API_KEY, 'Content-Type': 'application/json' } # Step 1: Create a monitor with schedule monitor_data = { "name": "Daily Monitor Test", "collection": COLLECTION_ID, "environment": None, "schedule": { "interval": 1, "unit": "day", "time": "09:00" }, "workspace": WORKSPACE_ID } create_monitor_response = requests.post( 'https://api.getpostman.com/monitors', headers=headers, data=json.dumps({"monitor": monitor_data}) ) assert create_monitor_response.status_code == 201, f"Monitor creation failed: {create_monitor_response.text}" monitor_id = create_monitor_response.json()['monitor']['id'] # Step 2: Verify monitor schedule assert create_monitor_response.json()['monitor']['schedule']['interval'] == 1 assert create_monitor_response.json()['monitor']['schedule']['unit'] == 'day' assert create_monitor_response.json()['monitor']['schedule']['time'] == '09:00' # Step 3: Trigger a manual run run_response = requests.post( f'https://api.getpostman.com/monitors/{monitor_id}/run', headers=headers ) assert run_response.status_code == 201, f"Monitor run trigger failed: {run_response.text}" run_id = run_response.json()['run']['id'] # Step 4: Poll for run completion for _ in range(10): time.sleep(5) # wait 5 seconds before checking status_response = requests.get( f'https://api.getpostman.com/monitors/{monitor_id}/runs/{run_id}', headers=headers ) assert status_response.status_code == 200 run_status = status_response.json()['run']['status'] if run_status == 'completed': break else: assert False, 'Monitor run did not complete in expected time' # Step 5: Verify run results run_data = status_response.json()['run'] assert run_data['status'] == 'completed' assert run_data['summary']['failed'] == 0, f"Some requests failed: {run_data['summary']}" print('Monitor scheduling and run test passed successfully.')
This script uses the Postman API to automate monitor scheduling and execution verification.
First, it creates a monitor with a daily schedule at 9:00 AM and asserts the creation response is successful (status 201).
Then, it verifies the schedule details in the response to ensure correctness.
Next, it triggers a manual run of the monitor and checks the run creation response.
It polls the run status every 5 seconds up to 10 times to wait for completion.
Finally, it asserts the run completed successfully with no failed requests.
This approach uses explicit assertions and retries to handle asynchronous monitor runs, following best practices for API test automation.
Now add data-driven testing to create monitors with 3 different schedules (daily at 9:00, hourly at 15 minutes past, weekly on Monday at 10:00).
Practice
Monitor scheduling in Postman?Solution
Step 1: Understand what monitor scheduling does
Monitor scheduling runs API tests automatically without manual intervention.Step 2: Compare options with this purpose
Only To run API tests automatically at set times describes automatic running at set times, matching monitor scheduling.Final Answer:
To run API tests automatically at set times -> Option AQuick Check:
Monitor scheduling = automatic test runs [OK]
- Confusing manual triggering with scheduling
- Thinking scheduling creates tests
- Mixing sharing collections with scheduling
Solution
Step 1: Identify where scheduling is set in Postman
Scheduling is done in the Monitors tab by selecting a collection and setting frequency/time.Step 2: Check other options for correctness
The other options are incorrect because scheduling is not done via desktop app settings, scripts, or the Runner tab.Final Answer:
Go to Monitors tab, select collection, then set frequency and time -> Option DQuick Check:
Monitors tab = schedule location [OK]
- Trying to schedule in Runner tab
- Writing scripts to schedule
- Looking for schedule in desktop app settings
Solution
Step 1: Understand the schedule timing
The monitor runs daily at 9:00 AM UTC. Current time is Monday 8:00 AM UTC.Step 2: Calculate next run time
Since 9:00 AM is 1 hour ahead, the first run will be Monday at 9:00 AM UTC.Final Answer:
Monday at 9:00 AM UTC (in 1 hour) -> Option CQuick Check:
Next run = next scheduled time after now [OK]
- Assuming immediate run on creation
- Choosing next day instead of same day if time not passed
- Confusing current time with scheduled time
Solution
Step 1: Analyze the monitor schedule setting
If monitor runs only once a day despite setting every 2 hours, likely the frequency was set wrong.Step 2: Evaluate other options
API collection without tests still runs; Postman supports multiple runs per day; restarting app not needed.Final Answer:
The schedule frequency was set incorrectly to daily instead of every 2 hours -> Option AQuick Check:
Check schedule frequency matches intended run rate [OK]
- Assuming no tests stops runs
- Thinking Postman limits runs per day
- Restarting app fixes schedule issues
Solution
Step 1: Identify the required schedule
The API updates every weekday at 6 PM UTC, so monitor should run only Monday to Friday at that time.Step 2: Match options to requirement
Set monitor to run daily at 6 PM UTC and disable weekends sets daily at 6 PM and disables weekends, matching exactly. Set monitor to run every hour and add a test to skip weekends runs too often and relies on tests to skip. Set monitor to run weekly on Friday at 6 PM UTC runs only once a week. Set monitor to run daily at 6 PM UTC without any weekend restrictions runs on weekends too.Final Answer:
Set monitor to run daily at 6 PM UTC and disable weekends -> Option BQuick Check:
Schedule matches update days and time [OK]
- Running monitor on weekends unnecessarily
- Using tests to skip runs instead of schedule
- Setting weekly instead of daily schedule
Ready to prove it?
Pass the test and this pattern moves unknown
