0
0
Postmantesting~5 mins

Workflow sequencing in Postman

Choose your learning style9 modes available
Introduction

Workflow sequencing helps you run tests in a specific order. This makes sure each step happens only after the previous one finishes successfully.

When you need to create a user before testing login.
When you want to update data only after fetching it.
When you test a multi-step process like checkout in an online store.
When one API call depends on data from a previous call.
When you want to clean up test data after all tests run.
Syntax
Postman
pm.sendRequest(request, function (err, res) {
    // handle response here
});

Use pm.sendRequest inside a test or pre-request script to call another request.

Use environment or collection variables to pass data between requests.

Examples
This sends a login request and saves the token for later requests.
Postman
pm.sendRequest({
    url: 'https://api.example.com/login',
    method: 'POST',
    header: { 'Content-Type': 'application/json' },
    body: { mode: 'raw', raw: JSON.stringify({ username: 'test', password: 'test' }) }
}, function (err, res) {
    pm.environment.set('token', res.json().token);
});
This creates a user and saves the user ID for the next steps.
Postman
pm.sendRequest({
    url: 'https://api.example.com/user',
    method: 'POST',
    header: { 'Content-Type': 'application/json' },
    body: { mode: 'raw', raw: JSON.stringify({ name: 'John' }) }
}, function (err, res) {
    pm.environment.set('userId', res.json().id);
});
Sample Program

This example shows two steps: first creating a user, then getting that user's details. The second step waits for the first to finish and uses the user ID from it.

Postman
// Step 1: Create user
pm.sendRequest({
    url: 'https://api.example.com/users',
    method: 'POST',
    header: { 'Content-Type': 'application/json' },
    body: { mode: 'raw', raw: JSON.stringify({ name: 'Alice' }) }
}, function (err, res) {
    if (err) {
        console.log('User creation failed');
        return;
    }
    const userId = res.json().id;
    pm.environment.set('userId', userId);
    console.log('User created with ID:', userId);

    // Step 2: Get user details
    pm.sendRequest({
        url: `https://api.example.com/users/${userId}`,
        method: 'GET'
    }, function (err2, res2) {
        if (err2) {
            console.log('Failed to get user details');
            return;
        }
        console.log('User details:', res2.json());
    });
});
OutputSuccess
Important Notes

Always check for errors in callbacks to avoid silent failures.

Use environment or collection variables to share data between requests.

Workflow sequencing helps test real user flows step-by-step.

Summary

Workflow sequencing runs requests in order, passing data between them.

Use pm.sendRequest to call requests inside scripts.

This helps test multi-step processes reliably.