Skip to content

How To Use Postman To Post Json

API Testing Blog

How to send a JSON request with Postman

Postman is a powerful tool for API testing, and sending JSON requests is a fundamental part of working with APIs. This guide will walk you through the process of sending JSON requests with Postman, from basic setup to advanced techniques.

Let’s get started:

1. Setting up your Request

  1. Open Postman: Launch the Postman application or open the Postman web app.
  2. Create a new request: Click on the “New” button and select “Request” from the dropdown. This will open a new request tab.
  3. Set the request method to POST: Click on the dropdown next to the request name (usually “GET”) and select “POST.”
  4. Enter the API endpoint: In the address bar, type the URL of the API endpoint you want to send your JSON data to.

2. Constructing your JSON Payload

  1. Choose the Body tab: Under the address bar, switch to the “Body” tab.
  2. Select “raw” as the body type: In the “Body” tab, click on the dropdown and choose “raw.”
  3. Select JSON as the format: In the same dropdown, select “JSON” from the list of formats.
  4. Enter your JSON data: In the text editor, paste or type your JSON data. Make sure the JSON is valid and properly formatted.

Example JSON payload:

{
"name": "John Doe",
"age": 30,
"city": "New York"
}

3. Sending Your Request:

  1. Set authorization (if required): If the API endpoint requires authorization (like a token or API key), you’ll need to add it under the “Authorization” tab.
  2. Click “Send”: Once your request is ready, click on the “Send” button to send your request to the server.

4. Analyzing the response:

  1. Review the response body: Postman will display the response from the server. You can see the response code (e.g., 200 OK, 400 Bad Request) and the response body.
  2. Check the response headers: Explore the “Headers” tab to view additional information sent back from the server.
  3. Validate the response: Depending on your test, you may want to verify specific details of the response, like the status code, the presence of particular fields, or the values returned.

5. Exploring Postman’s Features for JSON Handling:

  • JSON Formatter (pretty print): Postman comes with a built-in JSON formatter. It helps to make your JSON data more readable.
  • Dynamic variables: Leverage Postman’s dynamic variables feature to store data (like API keys or user IDs) and dynamically include them in your JSON payload.
  • Pre-request scripts: Write JavaScript code in Pre-request scripts to prepare data for your request before sending it.
  • Test scripts: Use Postman’s Test scripts to check the response from the API and verify the success or failure of your request.

Example of Postman request:

Request:

  • URL: https://example.com/users
  • Method: POST
  • Body:
    {
    "name": "Jane Doe",
    "email": "jane.doe@example.com",
    "password": "password123"
    }

Response:

{
"id": 12345,
"message": "User created successfully."
}

Using dynamic variables in your JSON payload:

{
"name": "{{user_name}}",
"email": "{{user_email}}",
"password": "password123"
}
  • In this example, {{user_name}} and {{user_email}} are dynamic variables that you can define in the environment or as part of the request.

Conclusion

Postman simplifies the process of sending JSON requests for API testing. By following these steps and exploring advanced features, you can efficiently send JSON data and analyze the responses, enabling you to effectively test and validate your APIs. Remember, the possibilities are endless, and Postman is constantly evolving, so keep exploring to unlock its full potential.

API Testing Blog