This repository contains a set of utility functions designed to enhance the functionality and ease of use within Postman. These utilities provide various functionalities such as setting and getting variables, generating random data, handling responses, and more.
- Local Variable Management: Set and get local variables within Postman requests.
- Collection Variable Management: Set and get collection variables to be used across multiple requests.
- Random Data Generation: Generate random names, dates, TINs, phone numbers, and email addresses.
- Response Handling: Convenient methods to handle and manipulate API responses.
- Debug Logging: Enable debug logging to track the flow and state of your scripts.
To use these utility functions in your Postman collection:
- Copy the
getUtilsfunction from theutils.jsfile in this repository. - Paste the function into your Postman Pre-request Script or Tests tab.
- Initialize the utility functions by calling
getUtils(pm, true)wherepmis the Postman instance andtrueenables debug logging.
const utils = getUtils(pm, true); // Enable debug logging
// or
const utils = getUtils(pm, false); // Disable debug loggingutils.locals.set("variableName", "variableValue");
const value = utils.locals.get("variableName");utils.collection.set("key", "value");
const value = utils.collection.get("key");const firstName = utils.random.generateFirstName();
const lastName = utils.random.generateLastName();
const email = utils.random.generateEmail(firstName, lastName);utils.response.onSuccess(() => {
console.log("Request was successful!");
});
if (utils.response.isSuccess()) {
const responseData = utils.response.get();
console.log(responseData);
}const log = utils.getLog();
console.log(log);Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.