Parameters in Postman are values sent with an API request to provide input or additional information to the server. They help APIs identify resources, filter data, submit information, and control how a request is processed.
- Parameters can be passed through the URL, request body, headers, or form data.
- Common parameter types include query parameters and path parameters.
- Postman variables can be used to make parameter values dynamic and reusable.
Types of Parameters in Postman
The commonly used ways to pass parameters and request data in Postman are:
- Query Parameters: Pass values through the URL, commonly for filtering, searching, sorting, and pagination.
- Path Parameters: Identify a specific resource as part of the URL path.
- Request Body Data: Send data in the body of POST, PUT, or PATCH requests.
- Form Data: Send form fields and files using
multipart/form-data. - URL-Encoded Data: Send form data using
application/x-www-form-urlencoded. - Header Values: Send additional request information such as authorization tokens and content types.
Steps to Pass Parameters in Postman Requests
Step 1: Create a Collection
Open Postman and create a new collection. Give the collection a name, such as GFG.
Step 2: Create a New Request
Click the three-dot menu next to the collection name and select Add request.
Step 3: Enter the API Endpoint
Enter the API endpoint in the request URL field. The method used to pass parameters depends on the API requirements.
Example:
GET https://jsonplaceholder.typicode.com/posts
You can then add query parameters directly to the URL or through the Params tab.
Step 4: Pass Query Parameters
Query parameters are added to the URL after a question mark (?). Multiple query parameters are separated using an ampersand (&).
Syntax:
?parameter=value
Example:
https://jsonplaceholder.typicode.com/posts?id=1
Here, id is the query parameter and 1 is its value.
We can also add query parameters from the Params tab by entering the parameter name in the KEY field and its value in the VALUE field.
To add query parameters in Postman:
- Open the Params tab.
- Enter the parameter name in the KEY field.
- Enter its value in the VALUE field.
- Postman automatically adds the parameter to the request URL.
The resulting URL is:
https://jsonplaceholder.typicode.com/posts?id=1
Step 5: Pass Path Parameters
Path parameters are included as part of the URL path and are commonly used to identify a specific resource.
A path parameter is represented by a colon (:) followed by the parameter name.
Syntax:
/users/:id
Example:
https://jsonplaceholder.typicode.com/posts/:id
When id has the value 1, the request URL becomes:
https://jsonplaceholder.typicode.com/posts/1
Here, id identifies the specific post that the API should retrieve.
Step 6: Pass Request Body Data
Request body data is commonly used with POST, PUT, and PATCH requests to send information to the server.
To send JSON data:
- Select the appropriate HTTP method.
- Open the Body tab.
- Select raw.
- Choose JSON as the format.
- Enter the request data.
Example:
{
"title": "Post",
"body": "This is a test post",
"userId": 1
}
The API determines which fields are required and how the data should be structured.
Step 7: Pass Form Data
Form data is useful when an API expects fields or file uploads using multipart/form-data.
To add form data:
- Open the Body tab.
- Select form-data.
- Enter the field names and values.
- Select a file when the API requires file uploads.
Step 8: Pass URL-Encoded Data
URL-encoded data is used when the API expects the application/x-www-form-urlencoded content type.
To send it in Postman:
- Open the Body tab.
- Select x-www-form-urlencoded.
- Enter the parameter names and values.
Step 9: Pass Parameters Through Headers
Some request information is passed through HTTP headers rather than the URL or request body.
Example:
Authorization: Bearer <token>
Content-Type: application/json
To add headers in Postman:
- Open the Headers tab.
- Enter the header name in the KEY field.
- Enter the corresponding value in the VALUE field.
Headers are commonly used for authentication, content types, caching, and other request metadata.
Step 10: Use Variables for Dynamic Parameters
Postman variables allow you to store values and reuse them across requests.
Example:
{{base_url}}/users/{{user_id}}
If:
base_url = https://api.example.comuser_id = 101
Postman sends the request as:
https://api.example.com/users/101
Variables are useful when the same request needs to work with different environments or parameter values.
Step 11: Send and Verify the Request
- After adding the required parameters, click Send. Postman sends the request to the API and displays the server response in the Response section.
- Verify the response status, headers, and body to determine whether the request was processed as expected.
Common Errors When Passing Parameters in Postman
- Using an incorrect parameter name or value.
- Placing a parameter in the wrong location.
- Missing
?or&when constructing a query string manually. - Using an incorrect path parameter or resource ID.
- Sending data in the wrong body format.
- Missing required headers or authentication information.
- Using an incorrect
Content-Typefor the request body.
Example: Here, we will be passing Query parameters, we will send query parameters in this API like ?id=1 we will call API like:
https://jsonplaceholder.typicode.com/posts/?id=1
Example: Here, we will be passing Path parameters
https://jsonplaceholder.typicode.com/posts/:id