Ask a Question

Using dynamic templates in a REST API POST Request


Using dynamic templates in a REST API POST Request



Currently, I have a few templates that are to be used within a REST API POST request, all of which are JSON format.  The templates contain fields that need to be updated at the time of each call.


Question now is, how do I load the correct template prior to assigning values to the parameters within the template before the POST command without having to create multiple API endpoint requests for each of those templates.  The parameterised values are to be extracted from an Excel spreadsheet which will potentially also contain the information on which template is to be used.  They essentially use the same API endpoint.


I've read that you can create a datasource using directories and files within said directory, but that does not fit with my intended purpose.  The templates are to be loaded only when they are needed during the testing cycle as well as there is the possibility that there might be new template files that might need to be used in the future or that existing template files might need to be updated to cater for any future changes in testing.  Thus these files need to be dynamically read at runtime, especially if it was part of a CI/CD pipeline.


So, in a nutshell, I need to be able to read a spreadsheet from one Excel file and use one of its columns to determine which template I need to be using.  The template will contain the parameterised fields that then need to be filled from that spreadsheet using the corresponding columns.


Any suggestions..??

Community Hero

What do you mean by multiple templates?
If the method is one, the request should be same for all . Correct?

If using data source, the you can parameterize the request data for the respective fields.


@nmrao same REST API endpoint, but that endpoint processes requests that can contain different information.  That information is captured in at least 3 different JSON templates, each with parameterised fields that are updated with dynamic data.  The different templates and parameterised data are used based on different situations.  It is the same POST method to the same REST API endpoint, but depending on the situation, a different template needs to be loaded for the call with the parameterised fields correctly populated.  So, yes, the parameterised fields are populated from a data source which, no surprise, is an Excel file.  (thus my other post on that error)


All of these are client requirements, not mine.  But I have to automate the testing so that it can be done as part of a CI/CD pipline.


By the end of the whole exercise, I should be able to just plug the entire test suite into the CI/CD pipeline without even needing to fire up SoapUI and the testing will be automatically triggered whenever there is a new software build.  In fact, once the test suite is designed, I shouldn't need to use SoapUI to upate any test data since the test steps are the same.  Meaning I should be able to modify the number of dynamic templates or the amount of test data being used simply by altering the data files.

Possible to show samples of different templates for better understanding, need not be actual values.
On what basis so you choose which template to use for particular test?


Possibly here is what I can think of.
- have a groovy script test step before the current rest test step.
- since you knew the condition based on the current row of the data source, retrieve the respective template for the post request
- set the request to the following rest test step (I guess, sample code snippet available how to set request to the step from (have search from available scripts)

Showing results for 
Search instead for 
Did you mean: