Skip to content

How To Use Put Method In Postman

API Testing Blog

How to Use PUT Method in Postman for API Testing

Postman is a powerful tool for API testing, and the PUT method is essential for updating data on a server. This guide will walk you through the steps of using the PUT method in Postman, providing practical examples and sample code.

Understanding the PUT Request

The PUT method is used to update an existing resource on a server. It is idempotent, meaning that multiple identical requests will have the same effect as a single request.

Key characteristics of the PUT method:

  • Idempotent: Multiple identical requests do not change the outcome.
  • Updates an existing resource: It modifies an existing resource identified by its unique identifier (e.g., ID).
  • Complete resource replacement: The entire resource is replaced with the data provided in the request body.

How to Use PUT Method in Postman: A Step-by-Step Guide

  1. Open Postman and Create a New Request:

    • Open Postman and click on the “New” button to create a new request.
  2. Set the Request Method to PUT:

    • In the request builder, select “PUT” from the dropdown menu next to the URL field.
  3. Enter the Target URL:

    • Replace the placeholder URL with the actual API endpoint you want to update.
    • Example: https://api.example.com/users/123 (Replace with your actual URL).
  4. Set the Headers (Optional):

    • Click on the “Headers” tab.
    • Define the headers required for your API. This usually includes:
      • Content-Type: Specifies the data format of the request body (e.g., application/json).
      • Authorization: Provides authentication credentials if required.
  5. Create the Request Body:

    • Click on the “Body” tab.
    • Select the appropriate data type for your request body.
    • Common data types include:
      • raw: For sending plain text or formatted data (JSON, XML).
      • form-data: For sending form data.
      • binary: For sending files.
    • Example JSON Request Body:
    {
    "name": "Updated Name",
    "email": "updated.email@example.com"
    }
  6. Send the Request:

    • Click on the “Send” button to send the PUT request to the server.
  7. Inspect the Response:

    • The server will respond with a status code and potentially a response body.
    • Common status codes for successful PUT requests:
      • 200 OK: Successful update.
      • 201 Created: Resource created (if the PUT method is used to create a new resource).
    • Inspect the response body to verify the update was successful and any returned data.

Example: Updating a User Profile

Resource URL: https://api.example.com/users/123

Request Body (JSON):

{
"name": "Updated Name",
"email": "updated.email@example.com"
}

Headers:

  • Content-Type: application/json

Steps:

  1. Open Postman and create a new request.
  2. Select “PUT” as the request method.
  3. Enter the URL: https://api.example.com/users/123.
  4. Add the “Content-Type: application/json” header.
  5. In the “Body” tab, add the JSON request body.
  6. Click “Send”.

Expected Response:

  • Status Code: 200 OK
  • Response Body: (May include updated user details or a success message)

Troubleshooting PUT Requests

  • Incorrect URL: Double-check the URL and ensure it is correct and points to the specific resource you want to update.
  • Invalid Request Body: Make sure the request body contains the correct data format and structure required by the API. Use the raw option in Postman and format the data accordingly.
  • Missing or Incorrect Headers: Ensure all necessary headers, such as Content-Type and Authorization, are included and have the correct values.
  • Permissions: Confirm that you have the necessary permissions to update the specified resource on the server.
  • Server Errors: Inspect the server response for error messages that can provide more details about the issue.

Conclusion

The PUT method in Postman is essential for updating existing resources within APIs. This guide provided a clear step-by-step process for using the PUT method, along with examples and troubleshooting tips. By understanding how to use the PUT method effectively, you can confidently test and interact with APIs for data update operations.

API Testing Blog