Skip to content

What Mine Was Used In The Postman

API Testing Blog

Understanding the Power of “What Mine” in Postman

Postman is a powerful tool for API testing, and one of its key features is the ability to store and manage environment variables. These variables, often referred to as “mines,” allow you to dynamically configure your API requests and responses, making your tests more adaptable and maintainable.

Demystifying “What Mine”

“What Mine” is a colloquial term often used within the Postman community. It essentially means “What environment variable should I use?” When you’re working with different environments (like development, testing, or production), each environment might have different API endpoints, authentication credentials, or other configurations. This is where “mines” come in handy.

The “What Mine” Workflows in Postman

1. Defining Environment Variables

Here’s how to define environment variables in Postman:

  • Go to the “Environment” tab: Click on the “Environment” icon in the top-right corner of your Postman workspace.

  • Create a new environment: Click on the “Add Environment” button.

  • Name your environment: Give your environment a clear, descriptive name like “Development,” “Staging,” or “Production.”

  • Add variables: Enter the variable name and the corresponding value for that environment. For example:

    Variable NameValue
    API_URLhttps://api.development.example.com
    API_KEYyour_dev_api_key

2. Using Environment Variables in Your Requests

Once you’ve defined your environment variables, you can access them within your API requests using a simple syntax:

  • Within the request URL: Replace hardcoded values with {{variable_name}}. For instance:

    GET https://{{API_URL}}/users
  • Within request headers: Use the same syntax to dynamically set headers. For example:

    {
    "Authorization": "Bearer {{API_KEY}}"
    }
  • Within the request body (if applicable): Utilize environment variables in your request payload. For example:

    {
    "username": "test_user",
    "email": "test_user@example.com",
    "password": "{{PASSWORD}}"
    }

3. Switching Between Environments

To switch between different environments in Postman, just select the desired environment from the dropdown in the “Environment” tab. Your requests will automatically use the variables defined for that environment.

Practical Example: “What Mine” for Authentication

Let’s consider a scenario where you’re testing an API that requires authentication.

Step 1: Define environment variables:

  • Development:

    • Variable Name: AUTH_TOKEN
    • Value: your_dev_token
  • Production:

    • Variable Name: AUTH_TOKEN
    • Value: your_prod_token

Step 2: Use the variable in your requests:

GET https://api.example.com/users
Authorization: Bearer {{AUTH_TOKEN}}

When you switch between environments, Postman will automatically replace {{AUTH_TOKEN}} with the corresponding token for the chosen environment.

”What Mine” and Test Collections

You can further enhance your API testing workflows by using environment variables with Postman collections. Collections act as containers for a series of related requests, making it easier to organize and execute tests.

Step 1: Create a collection:

  • Create a new collection in Postman by clicking on the “New Collection” button.
  • Give your collection a meaningful name (e.g., “User API Tests”).

Step 2: Add requests to your collection:

  • In your collection, create a new request for each API endpoint you want to test.
  • Remember to use environment variables in the request URLs, headers, and bodies, as demonstrated in previous examples.

Step 3: Add a test script to your collection:

  • Write tests within your collection to verify the expected API behavior.
  • Access environment variables in your test scripts using the pm.environment object.

Code Example:

pm.test("Verify API response status code", function () {
pm.response.to.have.status(200);
});
pm.test("Verify response body contains 'success'", function () {
pm.expect(pm.response.text()).to.include('success');
});
pm.test("Verify user ID is present", function () {
pm.expect(pm.response.json().data.id).to.be.a('number');
});

Conclusion

By leveraging environment variables, you can streamline your API testing process and avoid hardcoding sensitive data into your tests. This practice, often referred to as “What Mine,” is integral to creating robust and adaptable API testing workflows in Postman.

API Testing Blog