Wednesday, 8 May 2019

How to call a request before executing an API call in postman?

Add the below code in the Pre-request Script tab

pm.sendRequest({
    url: "http://localhost:8080/login",
    method: 'POST',
    header: {'Content-Type': 'application/json'},
    body: {
        mode: 'raw',
        raw: JSON.stringify({
            username: postman.getEnvironmentVariable("username"),
            password:postman.getEnvironmentVariable("password") })
    }
}, function (err, res) {
    postman.setEnvironmentVariable("userId", res.json().userId);
});

Reference: https://gist.github.com/madebysid/b57985b0649d3407a7aa9de1bd327990

No comments:

Post a Comment

The total number of locks exceeds the lock table size

 SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; SET GLOBAL innodb_buffer_pool_size = 2147483648;  -- 2GB Note: The value is in byte...