Calling API by parameter
Now we will call a GET API having parameters in its path
Add another HTTP Request
Set following configuration:
protocol[http]: https
Server Name or IP: customer-test-api.herokuapp.com
Port Number: 443
Method: POST
Path: /customer/api/v1/get/101
Here, 101 is an ID parameter that will fetch the information of 101 no. customer
Then click on play button
Previous 2 HTTP Request gets passed but current Request failed.
Response code is showing 401 and Response message is showing unauthorized
Reason is, immediate previous request has the token from previous authorization configuration but the last one has not.
So disable the previous HTTP Request. Then clear the result and run again

Now showing two request has been passed. The first request is for login, and second request is our parameterized API
Now let’s fix our issue so that we can run all the requests.
Adding Simple Controller
Drag and drop the HTTP Header Manager to the top of the all files.
Then add simple controller by right click on Thread Group and go to
Add > Logic Controller > Simple Controller

Add these 3 times and drag and move the HTTP Requests in it.
Follow the image:

Now, its tough to identify the HTTP Requests
Edit the HTTP Request names is as following way:

Now, it’s clearly understandable that what the API’s are.
Now enable the List API, previously you have disabled it to run the next API

Now clear the history and click the run button
You will see that, all API’s gets passed

Assert Expected Result
Now, we will match/assert our expected data with the API response
Suppose, we will match that, if our response data match with id 101 in the response body, then the API result will true
You will find the response in HTTP Request > Response Data > Response Body

Right-click on the Get Info API HTTP Request and go to Add > Assertions > Response Assertion

Then select Field to Test as “Text Response” and Pattern Matching Rules as “Contains“
Then click on Add button and set value 101 (expected data) so that we can match the response value with our expected data.
Now clear previous result and run it
Click on “View Results Tree” and see all succeeded

If we do not get proper response, then the assertion will fail
User Defined Variables
Now we will modify our configurations so that it could be more friendly while our project will get bigger.
Right-click on Thread Group and go to Add > Config Element > User Defined Variables

Drag and move it to the top of all the files. Then add baseUrl and its value like below picture

Now, click on “Login API” and set the base URL value to ${baseUrl}

We did this so that if our base URL gets changed, we don’t need to change the URL from the multiple places. Rather we just set the value in our user defined variables and we will get the instant change in all the HTTP Requests.
Now do the same thing for our another HTTP Requests.


Now clear the previous result and run it

You will see that all requests has been succeed
Now if you do error in baseUrl, then all requests will be failed as all request are fetching baseUrl from the user defined variables.

Now clear the result and run it again

All results gets failed as I said before. So, you understood what’s the use of User Defined Variables. Don’t forget to correct the base URL
Leave a Reply