Create and run a simple Postman flow to send a GET request and verify response
Preconditions (3)
✅ Expected Result: The flow runs successfully, sending the GET request and the test node verifies the response status code is 200, showing a pass result
const pm = require('postman-collection'); // Create a new flow const flow = new pm.Flow({ name: 'Simple GET Request Flow' }); // Create a request node const requestNode = flow.addNode('Request', { method: 'GET', url: 'https://jsonplaceholder.typicode.com/posts/1' }); // Create a test node const testNode = flow.addNode('Test', { testScript: `pm.test('Status code is 200', function () { pm.response.to.have.status(200); });` }); // Connect request node to test node flow.connect(requestNode, testNode); // Run the flow flow.run().then(() => { console.log('Flow executed successfully'); }).catch(err => { console.error('Flow execution failed:', err); });
This script creates a Postman flow programmatically.
First, it creates a new flow named 'Simple GET Request Flow'.
Then, it adds a Request node configured to send a GET request to the specified URL.
Next, it adds a Test node with a test script that checks if the response status code is 200.
The Request node is connected to the Test node to ensure the test runs after the request.
Finally, the flow is executed with flow.run(), and success or failure is logged.
This approach follows best practices by keeping nodes clear and connecting them logically.
Now add data-driven testing with 3 different URLs to send GET requests and verify status 200
pm.environment.set('token', pm.response.json().access_token);token after this runs if the response JSON is {"access_token": "abc123"}?pm.request.headers.add({key: 'Authorization', value: 'Bearer ' + pm.environment.get('token')});Pass the test and this pattern moves unknown