Postman Tutorial Part 5 – Sending POST Request in Postman

Introduction

As a part of Postman Tutorial – End to End, in this post, we will learn How to send POST request in the Postman tool.

Prerequisite

  1. You should have a preferably native Postman app installed on your system.

Sample APIs for Testing

  1. Restful-booker API
  2. GoRest API

I will use below POST APIs for this post to show the demo:-

  1. Create Booking – Creates a new booking
  2. Create User – Create a new user

Let’s explore and understand our example APIs.

Create Booking API

URI – https://restful-booker.herokuapp.com/booking

HTTP Method – POST

Headers – Content-Type: application/json

Authorization – Not required

Request Payload – Edit data as you wish but do not change key name or add/remove keys.

{
    "firstname" : "Jim",
    "lastname" : "Brown",
    "totalprice" : 111,
    "depositpaid" : true,
    "bookingdates" : {
        "checkin" : "2018-01-01",
        "checkout" : "2019-01-01"
    },
    "additionalneeds" : "Breakfast"
}

Create User API

URI – https://gorest.co.in/public-api/users/

HTTP Method – POST

Headers – Content-Type: application/json

Authorization – Bearer – Access Token

To get an access token you need to login to GoRest. Once you login using GMail or Facebook, you can get your access token.

Request Payload

{
  "name": "Tenali Ramakrishna",
  "gender": "Male",
  "email": "tenali.ramakrishna@15ce.com",
  "status": "Active"
}

Basics of POST – HTTP method

An HTTP POST method is used to create a new resource in the collection of resources with a request body passed as a JSON/XML or in a different format. If a resource is created successfully by the endpoint or server, it returns a status code 201( Created) (Not always) and returns the response body. It may return 200 (OK) and 204 (No Content) status code as well based on how API is developed.

POST is not a safe method as it is related to data creation. It is also not idempotent and invoking two identical POST requests may result in two different resources containing the same information with just different resource ids. An API may have a check on duplicate records as well like email id or mobile number is not unique. In that case, a POST request may behave as idempotent.

A request body contains data that is used to create a new resource. For example – You want to register a user on some portal and you need to pass your name, age, and address. Here name, age, and address are parameters/keys that hold a value in a request body.

Step by step process to hit a POST request in Postman

  1. Launch the Postman tool app.
  2. Open “Create a new request” template.
  3. Select the “POST” in HTTP methods dropdown.
  4. Pass the request URI in the address bar of Postman.
  5. Pass request payload
  6. Add authorization if applicable.
  7. Add headers if applicable.
  8. Click on “Send” button.
  9. View the response body and other details.

I will demo Create Booking API followed by Create User API.

Create booking API – Demo

Launch the Postman tool app

Launch the installed Postman tool. If you have not installed the Postman tool then you can install it from here. Please note here that I have created an account on Postman. If you have not created then you will be seeing some slightly different screen from below:-

Open Create a new request template

There are many ways to open a request template in Postman. You can use any option shown below:-

A request template will be shown as below:-

Select the “POST” in HTTP methods dropdown

Pass the request URI in the address bar of Postman

Pass request payload

Since a POST request is responsible to create a new resource, it requires data to work on. A POST API may ask for data in multiple ways. Our both example APIs take a JSON payload as a body.

To pass a JSON payload as body follow the below steps:-

  1. Click on “Body” tab.
  2. Select “raw” radio button.
  3. Select “JSON” from the last dropdown.
  4. Copy-paste JSON body in the body text area.

Add authorization if applicable

Create Booking API does not require any authentication. So I will skip this step. But for Create User API we require authentication which we will see after sometimes.

Add headers if applicable

Headers represent the metadata of API requests and responses. A header is a key-value pair. Our example APIs accept a request payload as JSON which we need to let server know explicitly by adding a header named (key) “Content-Type” with value as “application/json”. All required header information will be provided in API doc by the developer. If it is not provided you need to ask them.

To add a header, follow the below steps:-

  1. Click on “Headers” tab.
  2. Enter header name as key in a row.
  3. Enter header value as value in corresponding row.

Postman will start giving suggestions while typing header names and values.

I have added only one header but it shows count as 10. Actually, Postman adds some default headers automatically which are hidden by default. You can see those by clicking on “9 hidden” which you can see in the above image.

Click on “Send” button

Click on “Send” button and it will change to “Sending“. It means you need to wait until the response of API is received. Once request is processed you will get response below.

View the response body and other details

The Postman tool shows the response received in a Response section with status code, time taken to get a response, and size of the response.

Create user API – Demo

For Create User API, follow the same steps as above. For “Authorization” step, we need to have an extra setup for this API as it requires authorization.

Details of the authentication mechanism of an API are provided in API doc. GoRest API’s authentication mechanism is provided on their website as below:-

There are three ways to pass authentication. We will Oauth2. Follow the steps as below:-

  1. Click on “Authorization” tab.
  2. Select “OAuth 2.0” in “Type” dropdown.
  3. Get the access token after creating an account on GoRest as shown above and paste in “Access Token” text box.

Note – I have just hide my access token by using stars(*).

Response is as below once you hit “Send” button.

You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related posts here, all API manual and automation related posts here, and find frequently asked Java Programs here.

Many other topics you can navigate through the menu.

9 thoughts on “Postman Tutorial Part 5 – Sending POST Request in Postman

  1. Thanks Amod.. Looks like the input have been changed now for the API by original site… So you can just update these 2 things

    Input body is below now

    {
    “email”:”abc1234@gmail.com”,
    “name”:”gaurav khurana”,
    “status”:”Active”,
    “gender”:”Female”
    }

    Also as part of authorisation use the drop down as Bearer Token..

    Using the above 2 i was able to get the below output

    {
    “code”: 201,
    “meta”: null,
    “data”: {
    “id”: 1737,
    “name”: “gaurav khurana”,
    “email”: “abc1234@gmail.com”,
    “gender”: “Female”,
    “status”: “Active”,
    “created_at”: “2020-09-23T12:41:30.410+05:30”,
    “updated_at”: “2020-09-23T12:41:30.410+05:30”
    }
    }

  2. So I realize this reply is to an article that’s two years old, but thought I’d ask anyway:

    When I try to run the POST request I get a 404 error. I’ve acquired a access token and have tried it both as OAuth 2.0 and Bearer Token but neither one works. However, when I add the access token as a part of the URL directly – only then will it work. I’ve checked for extra spaces or carraige returns in the access token field but there aren’t any.

    If the author can provide an answer that’d be awesome but if not then at least I’m sharing my experience and what worked for anyone else who may be using these wonderful tutorials :).

  3. Sorry for the late response.. please find below details.

    Request:
    {
    “email” : “abc@gmail.com”,
    “fist_name” : “rudra”,
    “last_name” : “desai”,
    “gender”: “male”
    }

    Response:
    {
    “_meta”: {
    “success”: true,
    “code”: 200,
    “message”: “OK. Everything worked as expected.”,
    “totalCount”: 1976,
    “pageCount”: 99,
    “currentPage”: 1,
    “perPage”: 20,
    “rateLimit”: {
    “limit”: 30,
    “remaining”: 29,
    “reset”: 2
    }
    },
    “result”: [
    {
    “id”: “1163”,
    “name”: “Violet Schiller”,
    “gender”: “female”,
    “dob”: “1933-05-15”,
    “email”: “greg.stamm@farrell.com”,
    “phone”: “1-505-369-9119 x70733”,
    “website”: “http://www.roberts.com/voluptatem-voluptas-voluptatem-nulla-explicabo-animi-deleniti-molestias.html”,
    “address”: “1419 Hackett Street\nWeberburgh, VA 83007-0670”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1163”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?71253”
    }
    }
    },
    {
    “id”: “1165”,
    “name”: “Manuela Bradtke”,
    “gender”: “male”,
    “dob”: “2008-12-28”,
    “email”: “sydnie06@hotmail.com”,
    “phone”: “764-344-4424 x675”,
    “website”: “http://www.schmidt.com/”,
    “address”: “149 Watsica View Apt. 367\nNorth Joesph, GA 23686”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1165”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?11440”
    }
    }
    },
    {
    “id”: “1166”,
    “name”: “Danny Bayer”,
    “gender”: “male”,
    “dob”: “1992-11-02”,
    “email”: “braun.brennon@hotmail.com”,
    “phone”: “337-978-0772”,
    “website”: “http://www.brekke.com/neque-ducimus-ut-facilis-consequuntur-in-reprehenderit”,
    “address”: “468 Lawrence Ville Suite 654\nWest Hillard, FL 58367”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1166”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?19681”
    }
    }
    },
    {
    “id”: “1167”,
    “name”: “Dante Hahn”,
    “gender”: “male”,
    “dob”: “1932-07-17”,
    “email”: “mohr.carleton@ankunding.com”,
    “phone”: “+19485282501”,
    “website”: “http://www.upton.com/rem-laboriosam-distinctio-dolor-nemo-dolor”,
    “address”: “92996 Ryley Fields Suite 812\nLake Cleveland, IA 47485-0255”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1167”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?75727”
    }
    }
    },
    {
    “id”: “1168”,
    “name”: “Jo Spencer”,
    “gender”: “male”,
    “dob”: “2016-03-28”,
    “email”: “keeling.sonia@pfannerstill.com”,
    “phone”: “610.998.3495 x19634”,
    “website”: “http://www.ratke.biz/”,
    “address”: “2850 Lynch Grove Apt. 862\nEbertberg, RI 26178”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1168”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?77523”
    }
    }
    },
    {
    “id”: “1169”,
    “name”: “new user Monahan”,
    “gender”: “female”,
    “dob”: “1999-01-28”,
    “email”: “muriel56@hotmail.com”,
    “phone”: “(294) 647-5495”,
    “website”: “http://www.zieme.com/nesciunt-sapiente-soluta-et-non”,
    “address”: “6777 Dietrich Vista Apt. 505\nSchaeferfurt, HI 82988”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1169”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?78437”
    }
    }
    },
    {
    “id”: “1170”,
    “name”: “Talon Reichel”,
    “gender”: “male”,
    “dob”: “1931-10-08”,
    “email”: “alex52@keebler.net”,
    “phone”: “+1-643-244-5213”,
    “website”: “http://www.jerde.com/sint-reprehenderit-corporis-dolorem-dolorem-rem-et-tempora.html”,
    “address”: “459 Skye Village\nPort Minervahaven, AR 61362-8994”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1170”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?59502”
    }
    }
    },
    {
    “id”: “1171”,
    “name”: “Clementina Stamm”,
    “gender”: “female”,
    “dob”: “1936-05-22”,
    “email”: “johns.davonte@nolan.com”,
    “phone”: “863.309.3431 x84195”,
    “website”: “http://orn.org/iste-minima-dolorem-ullam-ea”,
    “address”: “5946 Dooley Circle Apt. 461\nPort Alexstad, DC 96664-7527”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1171”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?80315”
    }
    }
    },
    {
    “id”: “1172”,
    “name”: “Claude Stoltenberg”,
    “gender”: “male”,
    “dob”: “2006-02-08”,
    “email”: “giles.batz@hotmail.com”,
    “phone”: “573-984-2328 x235”,
    “website”: “http://www.okon.biz/pariatur-deleniti-quos-a-sed-at-corrupti-ut”,
    “address”: “1946 Volkman Point Suite 796\nJohathanview, TN 74717”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1172”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?35592”
    }
    }
    },
    {
    “id”: “1173”,
    “name”: “Florine Gerhold”,
    “gender”: “female”,
    “dob”: “2011-07-18”,
    “email”: “bechtelar.bernardo@gmail.com”,
    “phone”: “540.351.2836 x0825”,
    “website”: “http://swift.com/quam-consequatur-soluta-architecto-voluptatem”,
    “address”: “8053 Matteo Run\nNew Brennan, KY 47469-4190”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1173”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?74236”
    }
    }
    },
    {
    “id”: “1174”,
    “name”: “Roberta Dicki”,
    “gender”: “female”,
    “dob”: “1994-07-30”,
    “email”: “agraham@yahoo.com”,
    “phone”: “787.260.4651 x4967”,
    “website”: “http://olson.biz/labore-ut-nulla-earum-non-mollitia-minima”,
    “address”: “603 Bauch Spurs\nEast Reagan, DE 37026”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1174”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?89748”
    }
    }
    },
    {
    “id”: “1175”,
    “name”: “new user Boyer”,
    “gender”: “female”,
    “dob”: “1973-02-04”,
    “email”: “ecarroll@glover.com”,
    “phone”: “410-665-5780 x223”,
    “website”: “http://padberg.com/voluptas-voluptas-illum-officiis-repellat.html”,
    “address”: “7643 Effertz Lock\nWest Ansel, NY 57963”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1175”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?77588”
    }
    }
    },
    {
    “id”: “1176”,
    “name”: “Angelica Daugherty”,
    “gender”: “female”,
    “dob”: “2004-07-17”,
    “email”: “schroeder.dixie@gmail.com”,
    “phone”: “(367) 712-7461 x7672”,
    “website”: “https://www.hamill.com/saepe-ut-necessitatibus-architecto-dolorum”,
    “address”: “3026 Olson Spurs\nBatzstad, NY 66492-8255”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1176”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?69921”
    }
    }
    },
    {
    “id”: “1177”,
    “name”: “Freddie Keebler”,
    “gender”: “male”,
    “dob”: “1940-07-25”,
    “email”: “kaleigh.kohler@west.com”,
    “phone”: “+1 (853) 617-3263”,
    “website”: “http://www.leffler.com/”,
    “address”: “215 Domenic Plain Apt. 417\nScarlettburgh, IA 21137”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1177”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?75511”
    }
    }
    },
    {
    “id”: “1178”,
    “name”: “Sterling Baumbach”,
    “gender”: “male”,
    “dob”: “1945-11-30”,
    “email”: “hilll.antwon@gmail.com”,
    “phone”: “(514) 866-3572 x35357”,
    “website”: “http://frami.com/qui-libero-voluptas-dolore-qui-ipsam-debitis”,
    “address”: “5769 Lonie Court\nHudsonside, SC 65679-9782”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1178”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?20618”
    }
    }
    },
    {
    “id”: “1179”,
    “name”: “Tobin Ratke”,
    “gender”: “male”,
    “dob”: “1951-03-06”,
    “email”: “imorissette@barton.com”,
    “phone”: “661.748.3845 x0321”,
    “website”: “http://weber.com/non-et-voluptatem-beatae-molestiae-illo-vero-consequuntur”,
    “address”: “4272 Shanahan Land Suite 556\nDeannastad, PA 98459-7280”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1179”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?15803”
    }
    }
    },
    {
    “id”: “1180”,
    “name”: “Alessandra Dibbert”,
    “gender”: “female”,
    “dob”: “1927-12-06”,
    “email”: “fdubuque@altenwerth.com”,
    “phone”: “+1-447-859-7117”,
    “website”: “http://altenwerth.net/aliquid-non-neque-eos”,
    “address”: “6626 Daugherty Harbors\nSchulistberg, IN 37062”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1180”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?40646”
    }
    }
    },
    {
    “id”: “1181”,
    “name”: “Estelle Harber”,
    “gender”: “female”,
    “dob”: “1920-09-11”,
    “email”: “pzieme@romaguera.com”,
    “phone”: “610-331-5941”,
    “website”: “http://www.klein.com/minus-autem-est-laborum-sed-amet”,
    “address”: “1281 Piper Islands Suite 475\nNew Jaysonville, NE 52818-9942”,
    “status”: “inactive”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1181”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?45064”
    }
    }
    },
    {
    “id”: “1182”,
    “name”: “Coby Heidenreich”,
    “gender”: “male”,
    “dob”: “1972-09-03”,
    “email”: “coralie54@franecki.com”,
    “phone”: “459.479.5521 x5961”,
    “website”: “http://graham.info/officia-ratione-non-mollitia-molestiae-aperiam”,
    “address”: “3460 Bruen Burgs\nFunkshire, MN 26773-9354”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1182”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?15274”
    }
    }
    },
    {
    “id”: “1183”,
    “name”: “Mohamed Bogan”,
    “gender”: “male”,
    “dob”: “1936-05-07”,
    “email”: “boyle.dannie@hickle.com”,
    “phone”: “504-837-2094 x046”,
    “website”: “http://www.schimmel.com/eos-expedita-vel-repudiandae-explicabo-quaerat-assumenda-asperiores”,
    “address”: “935 Werner Mews Apt. 089\nEast Ludietown, SC 73165-2336”,
    “status”: “active”,
    “_links”: {
    “self”: {
    “href”: “https://gorest.co.in/public-api/users/1183”
    },
    “avatar”: {
    “href”: “http://lorempixel.com/250/250/people/?69745”
    }
    }
    }
    ]
    }

    1. In fact when we hit a post request, response shows user got created but it not added in list of users. These apis just for testing purpose without changing actual content.

Leave a Reply

Your email address will not be published. Required fields are marked *