Variable Usage in API | Zoho QEngine Help

Variable Usage in API

Prerequisite: Read the help document for variables to understand better.

Pass data in chained API requests

Use variables to extract data from the previous response and feed it to another request in API Testing.


  1. Source: Location from where the values will be extracted. You can select the source as HeaderStatus CodeXML Body, or JSON Body.
  2. Property:
    1. Header as the source: Specify the Header key as the property whose value will be assigned to the variable.
    2. JSON Body and XML Body as the source: Specify the JSON or XML path to extract a value.
  3. Variable: Name of the variable

Examples to extract data from JSON key-value response

  1. {
  2.    "id":1,
  3.    "name":"Leanne Graham",
  4.    "username":"Bret",
  5.    "address":{
  6.       "city":"Gwenborough",
  7.       "geo":{
  8.          "lat":"-37.3159",
  9.          "lng":"81.1496"
  10.       }
  11.    },
  12.    "phoneNumbers":[
  13.       {
  14.          "type":"home",
  15.          "number":"000-111-2222"
  16.       },
  17.       {
  18.          "type":"mobile",
  19.          "number":"111-222-3333"
  20.       },
  21.       {
  22.          "type":"office",
  23.          "number":"333-444-5555"
  24.       }
  25.    ]
  26. }

PropertyValue
usernameBret
address.cityGwenborough
phoneNumbers[0].number000-111-2222
phoneNumbers[-1].number333-444-5555
phoneNumber[*].number000-111-2222 (or) 111-222-3333 (or) 333-444-5555

Examples to extract data from JSON index-value response

  1. [
  2.       {
  3.          "type":"home",
  4.          "number":"000-111-2222"
  5.       },
  6.       {
  7.          "type":"mobile",
  8.          "number":"111-222-3333"
  9.       },
  10.       {
  11.          "type":"office",
  12.          "number":"333-444-5555"
  13.       }
  14.    ]

    PropertyValue
    [1].number111-222-3333
    [-1].typeoffice

XPATH Expressions

The following is a sample for XPath expressions
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <root>
  3.    <address>
  4.       <city>Gwenborough</city>
  5.       <geo>
  6.          <lat>-37.3159</lat>
  7.          <lng>81.1496</lng>
  8.       </geo>
  9.    </address>
  10.    <id>1</id>
  11.    <name>Leanne Graham</name>
  12.    <phoneNumbers>
  13.       <element>
  14.          <number>000-111-2222</number>
  15.          <type>home</type>
  16.       </element>
  17.       <element>
  18.          <number>111-222-3333</number>
  19.          <type>mobile</type>
  20.       </element>
  21.       <element>
  22.          <number>333-444-5555</number>
  23.          <type>office</type>
  24.       </element>
  25.    </phoneNumbers>
  26.    <username>Bret</username>
  27. </root>

Property Value
/root/username/text()Bret
/root/address/city/text()Gwenborough
/root/phoneNumbers/element[1]/number/text()000-111-2222
/root/phoneNumbers/element[3]/number/text()333-444-5555
/root/phoneNumbers/element/number/text()000-111-2222 (or) 111-222-3333 (or) 333-444-5555

Example to store data from the first response and feed it to the second request as a query param

We will make two GET requests in this example. The first request will return a JSON response in which each element contains an "id" key with values starting from 1. We will extract "id" value of the second element (so the extracted value is 2), store it in a variable named var, and use the variable as a query param in the second request.
Run API calls with the following data:

Request 1:

HTTP method: GET



Variables:

Source: JSON Body
Property: [1].id
Variable: var



Request 2:

HTTP method: GET



The following is a truncated view of the first response. The highlighted value of 'id' is what is extracted and supplied as a query param in the second request URL.



The following is the response of the second request, and you can see the second element from the previous response being returned. You can also see the variable value (2) in the second request URL.



Example using a global variable as base URL of the request

In Variables section, create a variable named baseurl and assign the value https://jsonplaceholder.typicode.com/ to it.



Supply the following values for the API request.

HTTP method: GET
URL: {{$baseurl}}users/



Run the test to view its response. You can also see the variable value inserted in the request URL.



  1. Variables



        Create. Review. Publish.

        Write, edit, collaborate on, and publish documents to different content management platforms.

        Get Started Now


          Access your files securely from anywhere

            Zoho CRM Training Programs

            Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

            Zoho CRM Training
              Redefine the way you work
              with Zoho Workplace

                Zoho DataPrep Personalized Demo

                If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

                Zoho CRM Training

                  Create, share, and deliver

                  beautiful slides from anywhere.

                  Get Started Now


                    Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                    BOOK A SESSION







                                Quick LinksWorkflow AutomationData Collection
                                Web FormsEnterpriseOnline Data Collection Tool
                                Embeddable FormsBankingBegin Data Collection
                                Interactive FormsWorkplaceData Collection App
                                CRM FormsCustomer ServiceAccessible Forms
                                Digital FormsMarketingForms for Small Business
                                HTML FormsEducationForms for Enterprise
                                Contact FormsE-commerceForms for any business
                                Lead Generation FormsHealthcareForms for Startups
                                Wordpress FormsCustomer onboardingForms for Small Business
                                No Code FormsConstructionRSVP tool for holidays
                                Free FormsTravelFeatures for Order Forms
                                Prefill FormsNon-Profit

                                Intake FormsLegal
                                Mobile App
                                Form DesignerHR
                                Mobile Forms
                                Card FormsFoodOffline Forms
                                Assign FormsPhotographyMobile Forms Features
                                Translate FormsReal EstateKiosk in Mobile Forms
                                Electronic Forms
                                Drag & drop form builder

                                Notification Emails for FormsAlternativesSecurity & Compliance
                                Holiday FormsGoogle Forms alternative GDPR
                                Form to PDFJotform alternativeHIPAA Forms
                                Email FormsFormstack alternativeEncrypted Forms

                                Wufoo alternativeSecure Forms

                                TypeformWCAG


                                    All-in-one knowledge management and training platform for your employees and customers.

                                              Create. Review. Publish.

                                              Write, edit, collaborate on, and publish documents to different content management platforms.

                                              Get Started Now




                                                                You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                    Manage your brands on social media


                                                                      • Desk Community Learning Series


                                                                      • Digest


                                                                      • Functions


                                                                      • Meetups


                                                                      • Kbase


                                                                      • Resources


                                                                      • Glossary


                                                                      • Desk Marketplace


                                                                      • MVP Corner


                                                                      • Word of the Day


                                                                      • Ask the Experts


                                                                        Zoho Sheet Resources

                                                                         

                                                                            Zoho Forms Resources


                                                                              Secure your business
                                                                              communication with Zoho Mail


                                                                              Mail on the move with
                                                                              Zoho Mail mobile application

                                                                                Stay on top of your schedule
                                                                                at all times


                                                                                Carry your calendar with you
                                                                                Anytime, anywhere




                                                                                      Zoho Sign Resources

                                                                                        Sign, Paperless!

                                                                                        Sign and send business documents on the go!

                                                                                        Get Started Now




                                                                                                Zoho TeamInbox Resources





                                                                                                          Zoho DataPrep Demo

                                                                                                          Get a personalized demo or POC

                                                                                                          REGISTER NOW


                                                                                                            Design. Discuss. Deliver.

                                                                                                            Create visually engaging stories with Zoho Show.

                                                                                                            Get Started Now








                                                                                                                                • Related Articles

                                                                                                                                • API Testing

                                                                                                                                  Overview In API testing users send a request to a third-party application and receive a response. The request contains information about the action you are performing and a response is returned for the same. Different HTTP methods let you perform ...
                                                                                                                                • Generate API keys in Zoho QEngine

                                                                                                                                  1. Overview Zoho QEngine provides secure methods to authenticate its interactions with external services. To facilitate this, QEngine supports API key generation, allowing users to create unique keys for secure communication between external services ...
                                                                                                                                • System Variables

                                                                                                                                  Overview Zoho QEngine provides certain built-in variables, referred to as System Variables, which represent dynamic elements of the system under test. They are pre-defined variables that enhance test case flexibility, ensuring more reliable and ...
                                                                                                                                • for each task

                                                                                                                                  1. Overview The for each block in Zoho QEngine is used to repeat a defined set of actions for every entry in a collection, allowing you to handle multiple items dynamically without writing duplicate steps. You can use it to iterate over static values ...
                                                                                                                                • Configuring Zia for Zoho QEngine

                                                                                                                                  What does this page cover Learn how to configure an AI model for Zia, Zoho QEngine's AI assistant, to enable capabilities such as generating manual test cases and test data. This page explains how to set up Zoho GenAI or connect external AI models ...
                                                                                                                                  Wherever you are is as good as
                                                                                                                                  your workplace

                                                                                                                                    Resources

                                                                                                                                    Videos

                                                                                                                                    Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                    eBooks

                                                                                                                                    Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                    Webinars

                                                                                                                                    Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                    CRM Tips

                                                                                                                                    Make the most of Zoho CRM with these useful tips.



                                                                                                                                      Zoho Show Resources