Data Path
The data saved in the data manager can be retrieved using an expression called data path. This can also be used to retrieve the data of a current API call.
Possible Locations
Syntaxes of Data Path
copy<resource_name>:<path> <!-- to access different resources --> <variable_name>:<path> <!-- to access current API call -->
Resource Name and Variable Name
For accessing a different resource, the data path should hold the resource name of whose data you are trying to access. Whereas, to access the current API call, you should provide any of the following two variables depending on your case.
- REQUEST: Contains the request details such as URL, params, headers and body.
- RESPONSE: Contains the response details like headers and body.
- The current API call’s data will be available only until the validation of that particular test case.
- In the condition-for-all attribute of <property>, you need not specify the variable REQUEST / RESPONSE. Because, the condition in data path will be applied to both the variables.
Path
This is similar to any JSON or XML path. For accessing the current API call’s data, following are a few path variables that will help you in navigating you to your desired key.
- REQUEST: url, headers, params, body
- RESPONSE: headers, body
Here is the list of path expressions that can be used in the ZSPEC,
Expression | Description |
---|---|
$ | The root object of your path. |
.property | It selects the specified property after the period (.) and you can continue adding the same expression. This will help you navigate to the child elements of the specified parent property. |
{condition} | The conditions specified in this expression will be applied to the preceding .property. If there is no property specified before the condition, it applies to all the response data. |
[n] | It helps you to select property of index ’n’. The possible values of ’n’ are integers and start from 0. |
[start_index - n] | It helps you to select the ’n’ number of data from the specified index range. i.e., [0-4] in this given expression the data path will fetch 4 records starting from 0th index. So, the result will be 0, 1, 2, 3. |
For using dynamic data within the {conditions} expression, you need not navigate from the data extraction path. You can simply provide the path, relative to which is used outside the {conditions} expression.
Samples
Data Path to access resources
Imagine that you want to use the data of trips resource, in one of your current resources. Following is the GET response of the trips resource,
- Resource name: trips
- Data Extraction Path: $.trips
- Primary Path: $.trip_id
copy{ "trips": [ { "trip_name": "London - Emily Jones", "trip_id": "5545984000000006873", "no_of_days": 10, "travelers": [ { "traveler_name":[ "Ms", "Emily", "Jones" ], "traveler_email": "emily@qke.com" } ] }, { "trip_name": "Sidney - John Smith", "trip_id": "5545974000000006871", "no_of_days": 2, "travelers": [ { "traveler_name":[ "Mr", "John", "Smith" ], "traveler_email": "johnsmith@abc.com" }, { "traveler_name":[ "Mr", "Patrick", "Robinson" ], "traveler_email": "patrobinson@abc.com" } ] } ] }
Now let us look at a few data path samples to access this data for your current resource.
Data Path | Result |
trips:$.no_of_days |
The value of no_of_days in the two records.
|
trips:$.travelers.traveler_email |
The value of the key traveler_email in the travelers JSON object.
|
trips:${travelers.traveler_name!=null}.trip_name |
Trip name of the records in which the traveler_email key in the travelers JSON object is not null. Result:
|
trips:$[1].trip_name |
The name of the 1st index record. |
trips:$[1-2].trip_id |
The trip ID of the records from index 1 to 2.
|
Data Path to access variables
Now, consider that you are writing ZSPEC for the trips resource and you need to access the data of trips resource from the current API call.
Request data
The request details of the trips resource’s current API call will be available like this.
REQUEST:
copy{ "url": { "module": "trips" }, "params": { "ids": "5545974000000006871,5545974000003954574,5545974000000002599" }, "headers" : { "Authorization":"Zoho-oauthtoken 1000.9b67d20xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0f0f6c9" }, "body" : null }
Let us look at how you have to access the request details of this API call.
Data Path | Result |
REQUEST:$.url.module |
The module name in the URL. |
REQUEST:$.params.ids |
The IDs that are provided in the URL parameter. |
REQUEST:$.headers.Authorization |
The details of headers in the request. |
Response data
The response details of this API call will be available for us to access as given below.
RESPONSE:
copy{ "headers" : { "Content-Language":"en-US", "Content-Type":"application/json;charset=UTF-8" }, "body" : { "trips": [ { "trip_name": "Bali - John Smith", "trip_id": "5545974000000006871", "no_of_days": 2 }, { "trip_name": "London - Emily Jones", "trip_id": "5545974000000006873", "no_of_days": 10 }, { "trip_name": "Sidney - Patrick Robinson", "trip_id": "5545974000000006875", "no_of_days": 5 } ] } }
Now, let us look at a few data path samples that can be used to retrieve this response data.
Data Path | Result |
RESPONSE:$.headers.Content-Type |
The value of Content-Type in the response header. |
RESPONSE:$.body.trips[2] |
The 2nd index value of trips in the response body.
|
RESPONSE:$.body.trips[1].trip_id |
The trip ID of the record in the 1st index of the response body. |
Last Updated 2025-05-30 16:54:59 +0530 +0530
Yes
No
Send your feedback to us