# Postman for Testing

## Why Use Postman for API Testing?

1. **User-Friendly Interface**:
   * Postman provides an intuitive and easy-to-use graphical user interface (GUI) for creating, testing, and managing API requests. This makes it accessible even for those who are not deeply technical.
2. **Comprehensive Testing Capabilities**:
   * Postman supports various types of API testing, including functional, integration, and regression testing. It allows you to create and run automated tests, ensuring your APIs work as expected.
3. **Environment Management**:
   * You can create different environments (e.g., development, staging, production) and manage environment-specific variables. This helps in testing APIs under different conditions without changing the code.
4. **Collaboration Features**:
   * Postman enables team collaboration by allowing you to share collections, environments, and test results with team members. This fosters better communication and coordination among development and testing teams.
5. **Integration with CI/CD Pipelines**:
   * Postman can be integrated into Continuous Integration/Continuous Deployment (CI/CD) pipelines, enabling automated testing as part of the development workflow. This helps in catching issues early and ensures the reliability of APIs.
6. **Detailed Documentation**:
   * Postman automatically generates API documentation, which can be shared with stakeholders. This documentation is interactive and helps in understanding the API endpoints and their usage.

## Is Postman Secure?

1. **Data Encryption**:
   * Postman uses modern Transport Layer Security (TLS) encryption algorithms to protect data in transit. All communications and data in transit over the internet are encrypted.
2. **Data Storage Security**:
   * Customer data is stored securely with high redundancy. Postman uses cryptographic methods and industry standards to protect data at rest, including AES-256-GCM encryption.
3. **Access Control**:
   * Postman provides features like role-based access control, API key management, and audit logs to ensure secure access to your data and API keys.
4. **Postman Vault**:
   * Sensitive data such as API keys, access tokens, and passwords can be stored securely in the Postman Vault. These vault secrets are only accessible to you and are not synced to the Postman cloud.
5. **Compliance and Best Practices**:
   * Postman's security program and processes are consistent with best practices and industry standards. They also provide guidelines for users to follow safe practices with their data and credentials.

Using Postman for API testing not only enhances your testing capabilities but also ensures that your data and API interactions are secure. If you have any more questions or need further details, feel free to ask!

### Postman Links&#x20;

The links below are provided for your convenience.  They are external Links and as such, Alemba maintains no care or control over these links.

[Postman Trust Center - Security](https://www.postman.com/trust/security/)&#x20;

[Postman Trust Center - Shared Responsibility](https://www.postman.com/trust/shared-responsibility/)&#x20;

[Postman API Testing Guide](https://www.postman.com/api-platform/api-testing/)&#x20;

[Postman API Testing Tool - Javatpoint](https://www.javatpoint.com/postman)

## **Setup Postman**

1. Download and install Postman.  [www.postman.com](https://www.postman.com)

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FyLKzR8P6nAL2m3GGU0EW%2Fimage.png?alt=media&#x26;token=fc4c96b7-c03d-4b46-a205-90b0a86f29d5" alt=""><figcaption></figcaption></figure>

2. Create a new environment in Postman with variables such as `UsernameTest`, `PasswordTest`, `SystemURLTest`, `Login_Token`, `CallRef`, `RequestRef`, and `TaskRef`.

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FTiziUrKiIlkWwZk62ruR%2Fimage.png?alt=media&#x26;token=61aa6431-56c9-42ee-98bb-548e8f95f0ee" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FkFut5RvQtDm0TzbYD3Nb%2Fimage.png?alt=media&#x26;token=67f21091-88bf-4430-b81b-a18868b2826e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FpA3hVhU2Asl40n5CFnxa%2Fimage.png?alt=media&#x26;token=b3221ef9-80eb-4293-b605-00550a975c7b" alt=""><figcaption></figcaption></figure>

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top"><strong>Variable Name</strong></td><td valign="top"><strong>Purpose</strong></td><td valign="top"><strong>Example</strong></td></tr><tr><td valign="top">UsernameTest</td><td valign="top">ASM Username</td><td valign="top">User1</td></tr><tr><td valign="top">PasswordTest</td><td valign="top">Password for ASM User</td><td valign="top">Password@1!</td></tr><tr><td valign="top">SystemURLTest</td><td valign="top">The base URL for your system</td><td valign="top">https://servername/systemname</td></tr><tr><td valign="top">Login_Token</td><td valign="top">Variable which stores auth token</td><td valign="top">23498t9h9h398hn4f4f3wjm4f300</td></tr><tr><td valign="top">CallRef</td><td valign="top">Call Number you want to query</td><td valign="top">23402708</td></tr><tr><td valign="top">RequestRef</td><td valign="top">Request Number you want to query</td><td valign="top">34590353</td></tr><tr><td valign="top">TaskRef</td><td valign="top">Task Number you want to query</td><td valign="top">720843024</td></tr></tbody></table>

{% hint style="info" %}
These variables can be used both in the URL of your HTTP requests but also in the body of the request being sent.&#x20;
{% endhint %}

### **Create a Collection**

Group your HTTP requests in a collection for better organization.

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FZYzo7aJFMhYt3URudhvg%2Fimage.png?alt=media&#x26;token=d066e846-441d-4e81-9a2c-97d23bb65c0c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2F8BvHZ4fbinNmJAFfYNxs%2Fimage.png?alt=media&#x26;token=92ef6d8c-b0e4-4cfa-a4b7-0211552b3923" alt=""><figcaption></figcaption></figure>

### **Create HTTP Requests**

Use the environment variables in the URL and body of your requests for consistency and ease of use.

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FZQL8SmFQCSs4wyihQtkh%2FScreenshot%202025-02-12%20at%2011.49.05.png?alt=media&#x26;token=7e3ce471-71fc-4744-973e-c9ee97e9aeb1" alt=""><figcaption><p>Click on New in the top left hand corner and select HTTP</p></figcaption></figure>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FOrSsZ2NigL07lSLqcz0q%2Fimage.png?alt=media&#x26;token=b8d36c5e-fab5-460f-996a-3b52e21372ef" alt=""><figcaption><p>Give your Request a name and make sure you select the environment for the request to be your New Test Environment and click Save</p></figcaption></figure>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2F2F9Di0SbScjfdQdRNUow%2Fimage.png?alt=media&#x26;token=366c1931-4f84-446e-9197-b4f72d7053be" alt=""><figcaption><p>On the Save request screen, select your New Test Collection and click Save at the bottom of the screen</p></figcaption></figure>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FKtvehkmZlfcJScdrIrVR%2Fimage.png?alt=media&#x26;token=01b708ed-6501-4d05-abef-02fe9276eb1f" alt=""><figcaption></figcaption></figure>

## Working with ASM and Postman <a href="#workingwithasmandpostman" id="workingwithasmandpostman"></a>

### Creating Your Authorization Token <a href="#creatingyourauthorizationtoken" id="creatingyourauthorizationtoken"></a>

1. Create a new HTTP request in Postman with the following details:
   * **Method**: POST
   * **URL**: `{{SystemURLTest}}/alemba.web/oauth/login`
   * **Headers**: `Content-Type: application/x-www-form-urlencoded`
   * **Body**: Include parameters such as `grant_type`, `scope`, `client_id`, `username`, and `password`.
2. &#x20;On the Authorization tab, select Inherit from parent.

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FJfNu34FCmSDUm2hwhfyf%2Fimage.png?alt=media&#x26;token=3a645f4b-8245-4e84-ace8-b645eeb5116d" alt=""><figcaption></figcaption></figure>

3. On the Headers tab, add the following Header row:

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Key</td><td valign="top">Value</td></tr><tr><td valign="top">Content-Type</td><td valign="top">application/x-www-form-urlencoded</td></tr></tbody></table>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FcU1HlyHnINXLEyPqxkh0%2Fimage.png?alt=media&#x26;token=93e8adf0-f9b4-4436-8698-5a22f4adb096" alt=""><figcaption></figcaption></figure>

4. On the Body tab, select the x-www-form-urlencoded radio button

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FidLBXMlt5sUEu9jsWWW6%2Fimage.png?alt=media&#x26;token=ef4c1749-b593-4cc1-bf32-6aa23f79ba7d" alt=""><figcaption></figcaption></figure>

5. Add the following parameters

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Key</td><td valign="top">Value</td><td valign="top">Description</td></tr><tr><td valign="top">Grant_type</td><td valign="top">Password</td><td valign="top"> </td></tr><tr><td valign="top">Scope</td><td valign="top">Session-type:Analyst</td><td valign="top"> </td></tr><tr><td valign="top">Client_id</td><td valign="top">&#x3C;replace this with Client ID obtained from API Explorer Admin Page e.g. 5157e300-0000-0000-0000-00000000001d ></td><td valign="top"> </td></tr><tr><td valign="top">Username</td><td valign="top">&#x3C;Here you can use the {{UsernameTest}} variable OR the actual username for your API account></td><td valign="top"> </td></tr><tr><td valign="top">Password</td><td valign="top">&#x3C;Here you can use the {{PasswordTest}} variable OR the actual password for your API account></td><td valign="top"> </td></tr></tbody></table>

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FYQ3YP3FZgapwq5AlqooT%2Fimage.png?alt=media&#x26;token=3f1fa9cd-f7a9-4d89-90f9-79aec4934e7d" alt=""><figcaption><p>Once you’ve added the params, your body should look like this</p></figcaption></figure>

6. Send the request to receive the authentication token, making sure that New Test Environment is selected.

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FLMdxDuAw3oXKwgw0ajLN%2Fimage.png?alt=media&#x26;token=89916c3c-9e8e-45b3-ba15-df6e4f03469e" alt=""><figcaption></figcaption></figure>

7. You should receive a response at the bottom of your request window

{% hint style="info" %}
**The line of code next to the “access\_token” is the authentication token itself.**
{% endhint %}

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FoCwvP7vJWG9x80JCt0i2%2Fimage.png?alt=media&#x26;token=431ce2b0-617e-416d-9432-ee5991ec1bbc" alt=""><figcaption></figcaption></figure>

### Passing the Token to your *Login\_Token* Variable

{% hint style="info" %}
This step ensures you can re-use your Token easily across all HTTP requests.
{% endhint %}

1. On the same HTTP request screen, go to the Tests tab
2. In the window underneath, enter this code:

   `var jsondata = JSON.parse(responseBody)`

   `pm.environment.set("Login_Token", jsondata.access_token);`

   1. Where Login\_Token is the name of the environment variable you created in your New Test Environment, to hold your token value.
3. Click **Send** again at the top of the page and now your access\_token value will be written to your your Login\_Token variable.&#x20;

<figure><img src="https://1375663122-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhlW9jKl7dcDggHAPhNU9%2Fuploads%2FRQWpIp8Fc2ClARi5iWJv%2Fimage.png?alt=media&#x26;token=d3306c9a-0e0f-409e-8d1a-e394981bf4e0" alt=""><figcaption></figcaption></figure>

m
