Forum Discussion

rg2018's avatar
rg2018
Occasional Contributor
7 years ago

parameterize json rest api request

Was wondering if anyone had input on best solution for parameterizing a json rest api request?

 

Here is what I'd like to parameterize: (sample request below)

MDOC_PRESENTED_QUESTION_ID

QUESTION

MDOC_ANSWER_ID

CHOICE_ID

CHOICE

 

Now I know there are the following datasource types to paramertize these:

Data Connection

Data Generator

Directory

Excel

File

Grid

Groovy

JDBC

Json

EML

 

I've tried Grid which seemed to require me to create seperate properties for each(so, questionid1, question1, answerid1, choiceid1, choice1, questionid2 etc etc etc....) and I also tried JDBC and was able to get first set of values for the first request block of question and choice ids via setting "prepared properties" for choiceid and answerid and then doing a query based on where clause = :QuestionID and :ChoiceID. This method seemed to be a challange vs grid since I need all differant values in the request for  :QuestionID and :ChoiceID and my query is only bringing back resutls for values set in the "prepared properties".

 

What would be the best route to take? Just stick with grid? Thinking of the most dynamic and least maintenance if values need to change etc....

 

 

 

sample Json request:

{
"mDOC_json_data": {
"mDOC_PRESENTED_QUESTION_json_dataList":
[{
"MDOC_PRESENTED_QUESTION_ID": 137,
"QUESTION": "Indicate_Persons_Overall_Health_Risk_137",
"ANSWER_LIST": [{
"MDOC_ANSWER_ID": 45,
"MDOC_PRESENTED_QUESTION_ID": 137,
"CHOICE_ID": 545,
"CHOICE": "Persons_Health_Conditions_Generally_Stable_545"
}]
},
{
"MDOC_PRESENTED_QUESTION_ID": 112,
"QUESTION": "HOSPITAL_Level_Of_Care_112",
"ANSWER_LIST": [{
"MDOC_ANSWER_ID": 202,
"MDOC_PRESENTED_QUESTION_ID": 112,
"CHOICE_ID": 75,
"CHOICE": "Certified_By_Physician_To_Require_Supports_Similar_To_Hospital_75"
}]
},
{
"MDOC_PRESENTED_QUESTION_ID": 82,
"QUESTION": "Clinical_Monitoring_Established_By_Persons_Physician_82",
"ANSWER_LIST": [{
"MDOC_ANSWER_ID": 100,
"MDOC_PRESENTED_QUESTION_ID": 82,
"CHOICE_ID": 314,
"CHOICE": "Person_Under_Clinical_Monitoring_Order_314"
}]
}],
"MDOC_ID": 12345,
"PERSON_ID": 965879,
"MC_REFERRAL_ID": 1322
},
"PERSON_ID": 965879,
"FIRST_NAME": "JOHN",
"MIDDLE_NAME": "M",
"LAST_NAME": "DOE",
"NAME_SUFFIX": "Sr."
}

  • Hi rg2018,

     

    I think using Grid is the best way if your TestData is static and never gonna change too frequently.

     

    But, if your Test Data changes too frequently then you must save your Data into the Excel sheet and just write the groovy code to import the sheet and import the data of that sheet into Properties Step so that you can use that data in your Request by parameterizing it.

     

    You can have a look at this link, to get an idea how to read data from excel via groovy.

     

    Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

     

    Thanks and Regards,

    Himanshu Tayal

     

     

  • Hi rg2018,

     

    I think using Grid is the best way if your TestData is static and never gonna change too frequently.

     

    But, if your Test Data changes too frequently then you must save your Data into the Excel sheet and just write the groovy code to import the sheet and import the data of that sheet into Properties Step so that you can use that data in your Request by parameterizing it.

     

    You can have a look at this link, to get an idea how to read data from excel via groovy.

     

    Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

     

    Thanks and Regards,

    Himanshu Tayal

     

     

    • Olga_T's avatar
      Olga_T
      SmartBear Alumni (Retired)

      Hi everyone,

      Thanks, HimanshuTayal, your assistance is much appreciated!

      rg2018, does the reply that Himanshu provided help you? 

       

      • rg2018's avatar
        rg2018
        Occasional Contributor

        Yes, that answered my question.

         


        Thanks!