Recently my team and I were discussing ways to speed up code reviews. Thats when Postman pop into my mind. With expected return values agreed upon, it’s much easier to test if api’s are working as they should. So when the senior dev needs to do code review he just needs to go through the checklist.
Lets get right into it. I need to test my backend api without using the ui.
So in-order to do that I open up google chrome developer tools & goto Network tab
I want to create a single contact so I need to watch the network to see what api request is being made.
create lead list
We see in the network tab: Request URL: http://localhost:1337/api/lead-list
and down below Request Payload
Let open up Postman now
2 steps: Change to POST & enter in URL: http://localhost:1337/api/lead-listf
Now for my api we require a token in the header
Add that to Postman
Now we to add the body: first get the Request Payload, click the view source then copy the Payload.
Now prepare finish our postman body
When I click Send I get an error
Because we created test 1 sms with the ui in-order to get the information for postman. So lets delete test 1 sms
Then send with postman again and we have a successful Lead List created
Just for show I changed the name to test 2 sms
In our Ui we see our created list names
Lets add a contact to the list. We will start by adding a single contact
I add my number and click create
Here is the network request
and the payload
We need to add this to Postman. In postman we need to create a new tab but an easier way is to duplicate the first tab
So after setting it up and send
There is one thing here we can automate and thats the lead_list_id
In the first post we received a response with id
Lets grab that response id and save it to a global variable
For goto the first tab created and click the tests tab. Here I pre-wrote some javaScript to get the json response and save it to a global variable id
After changing the Body to {“name”:”test 3 sms”} and running Send. The console shows us the json response.
Now go into the second tab and change lead_list_id value to “{{id}}” this id was set earlier as our global variable carrying the value: 5f8e711bdf4f8b003863adfa
So now we learned to take responses and set data into globals variables.
Next I want to automate sending of messages.
After filling out Campaign Name and To and Message there were network calls. We need to take those network calls and paste them into Postman like we did earlier.
Goto Postman and Duplicate a tab
Setup a POST Request
On Send we get a response of campaign id
We need to put campaign_id into a global variable and run it. This will but get the response campaign_id then put it into the global variable campaign_id.
Grab our next Request
Postman: Duplicate another tab
Add our global variables campaign_id & id to the Request URL and id:
On to the next Request
Duplicate a tab and add the Request URL and body. We add our global variable id in the URL itself {{messageid}}
Finally we capture the network call on Send. This is what we get
Setup our last tab on Postman. url with empty body
Lets test it all out. Lets save our test api’s
Create a collection
Save them in the order they were created and Click Runner
Click the test api collection
unclick the first 2 requests
Click Run test api and see the results. All green status 200
Will that was the basics of using Postman. I hope you learned something. Cheers.