Extracting Variables from API Response (2024)

Variables can be extracted from Test Case's responses and can be used in subsequent HTTP requests (test cases). To extract the variable's values from the test case's actual results, please follow the steps below:

  • Open the test case from which you want to extract variables
  • Go to the "Variable Extractor" sub-tab
  • In the JSON Path / XML Path / Utility Method column, you may provide
    • the JSON path of the API response if the response is in JSON format. For more information, please read JSON Path Syntax.
    • the XML path of the API response if the response is in XML format. For more information, please read XML Path Syntax.
    • utility method to extract data from any type of response. For more information, please read Extracting variable via utility methods.
  • in the Post Validation? column, By default the value is set to false, which means, the variable will be extracted before the response validation process. And you may use the extracted variables in the same test case during the response validation process. If you enable this flag then the variable will be extracted after the response validation process.

Let us take an example, how we can extract a variable from API response:

  • Suppose we have an API that creates resources on the server and returns the following JSON response:
{ "id": "54a79b704cba8d5328d087f5", "resource_name": "testcase", "resource_url": "http://vrest.io/i/demo/m/RVD/create_resource", "resource_description": "This API creates a resource on the server", "meta": { "created_at": "2015-01-03T07:41:21.000Z" }}
  • Now, we want to save the id of newly created resource into variable say "resourceId" and creation time into variable say "resourceCreatedAt". We can extract these variables in the following way:

Extracting Variables from API Response (1)

Few points regarding writing Path in the above table:

  • Each individual property value can be extracted via JSON path notation e.g. id or meta.created_id

  • For more information, read JSON Path syntax.

  • Now we can use these extracted variables in subsequent requests. Note that once a variable is defined, it can be used in all subsequent requests within that test run only. If you want to override this variable, simply re-define the variable in any request.

Suppose we have an API that updates this newly created resource and it needs the ID of the resource to update. We can use the {{resourceId}} variable (extracted in the previous step) in the URL as shown in the following figure:

Extracting Variables from API Response (2)

Notes:

  • Variable extraction feature is only applicable for JSON / XML responses at present using JSON / XML path.
  • For defining JSON path, follow the guide.
  • For defining the XML path, follow the guide.
  • If you want to extract variables from responses other than JSON/XML, then you need to write your own utility method to extract data from either response body or response headers. For more information on this, please read our guide on Extracting variable via Utility Methods.
Extracting Variables from API Response (2024)
Top Articles
108 Performance Review Phrases (With Examples) - Zippia
7 Things You Should Know If You Deposit More Than $10K Into Your Checking Account
Craigslist Monterrey Ca
Blackstone Launchpad Ucf
New Slayer Boss - The Araxyte
Air Canada bullish about its prospects as recovery gains steam
Craigslist Furniture Bedroom Set
Alpha Kenny Buddy - Songs, Events and Music Stats | Viberate.com
Noaa Swell Forecast
Emmalangevin Fanhouse Leak
What's Wrong with the Chevrolet Tahoe?
Carter Joseph Hopf
2013 Chevy Cruze Coolant Hose Diagram
Tripadvisor Near Me
Wunderground Huntington Beach
Miami Valley Hospital Central Scheduling
Pwc Transparency Report
Classic Lotto Payout Calculator
Truth Of God Schedule 2023
Slope Tyrones Unblocked Games
Swedestats
Aspen Mobile Login Help
Craigslist Portland Oregon Motorcycles
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Music Go Round Music Store
Integer Division Matlab
Phantom Fireworks Of Delaware Watergap Photos
City Of Durham Recycling Schedule
The Banshees Of Inisherin Showtimes Near Broadway Metro
Ullu Coupon Code
manhattan cars & trucks - by owner - craigslist
Albertville Memorial Funeral Home Obituaries
Little Caesars Saul Kleinfeld
Roadtoutopiasweepstakes.con
Ewwwww Gif
The Bold And The Beautiful Recaps Soap Central
Scanning the Airwaves
Jewish Federation Of Greater Rochester
Dwc Qme Database
Linkbuilding uitbesteden
Ghareeb Nawaz Texas Menu
Thothd Download
Suntory Yamazaki 18 Jahre | Whisky.de » Zum Online-Shop
Caesars Rewards Loyalty Program Review [Previously Total Rewards]
Greatpeople.me Login Schedule
Vci Classified Paducah
Sacramentocraiglist
Walmart Front Door Wreaths
Www Extramovies Com
Loss Payee And Lienholder Addresses And Contact Information Updated Daily Free List Bank Of America
Affidea ExpressCare - Affidea Ireland
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 6061

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.