EchoAPI Built-in Variables
EchoAPI's built-in system variables include the request
object and the response
object.
request Object
This object contains all the parameters of a request. You can print, view, and utilize this variable within pre-request scripts.
As shown in the above image, the structure of this object is as follows:
{
"id": "376c266efef0c6",
"name": "Update an existing pet",
"headers": {
"token": "{{token}}",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"user-agent": "PostmanRuntime-ApipostRuntime/1.1.0",
"connection": "keep-alive"
},
"method": "PUT",
"url": "https://petstore3.swagger.io/api/v3/pet",
"data": "{\n\t\"id\": 10,\n\t\"name\": \"Doogie\",\n\t\"category\": {\n\t\t\"id\": 1,\n\t\t\"name\": \"Dogs\"\n\t},\n\t\"photoUrls\": [\n\t\t\"\"\n\t],\n\t\"tags\": [\n\t\t{\n\t\t\t\"id\": 0,\n\t\t\t\"name\": \"\"\n\t\t}\n\t],\n\t\"status\": \"\"\n}",
"request_headers": {
"token": "{{token}}",
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"user-agent": "PostmanRuntime-ApipostRuntime/1.1.0",
"connection": "keep-alive"
},
"request_bodys": "{\"id\":10,\"name\":\"Doogie\",\"category\":{\"id\":1,\"name\":\"Dogs\"},\"photoUrls\":[\"\"],\"tags\":[{\"id\":0,\"name\":\"\"}],\"status\":\"\"}",
"request_querys": {},
"request_variables": {},
"mode": "json",
"uri": {
"protocol": "https",
"path": [
"api",
"v3",
"pet"
],
"host": [
"petstore3",
"swagger",
"io"
],
"query": [],
"variable": []
}
}
We can use this object to obtain the current API request parameters in the script, thereby achieving our goals.
response Object
This object contains all the response parameters of a request and is available only in post-response scripts (after the request has been sent). You can print, view, and use this variable in post-execution scripts.
The corresponding structure of this object is as follows:
{
"headers": {
"date": "Wed, 07 Aug 2024 10:03:54 GMT",
"content-type": "application/json",
"content-length": "116",
"connection": "keep-alive",
"access-control-allow-origin": "*",
"access-control-allow-methods": "GET, POST, DELETE, PUT",
"access-control-allow-headers": "Content-Type, api_key, Authorization",
"access-control-expose-headers": "Content-Disposition",
"server": "Jetty(9.4.53.v20231009)"
},
"cookies": {},
"raw": {
"responseText": "{\"id\":10,\"category\":{\"id\":1,\"name\":\"Dogs\"},\"name\":\"Doogie\",\"photoUrls\":[\"\"],\"tags\":[{\"id\":0,\"name\":\"\"}],\"status\":\"\"}",
"json": {
"id": 10,
"category": {
"id": 1,
"name": "Dogs"
},
"name": "Doogie",
"photoUrls": [
""
],
"tags": [
{
"id": 0,
"name": ""
}
],
"status": ""
},
"status": 200,
"responseTime": 247
},
"json": {
"id": 10,
"category": {
"id": 1,
"name": "Dogs"
},
"name": "Doogie",
"photoUrls": [
""
],
"tags": [
{
"id": 0,
"name": ""
}
],
"status": ""
}
}
response.raw: Raw Response Data
Usage example:
response.raw.status //Response status code (200, 301, 404, etc.)
response.raw.responseTime //Response time (milliseconds)
response.raw.type //Response type (json, etc.)
response.raw.responseText //Response text
response.json: JSON-formatted Response Data
Usage example as shown in the above example:
response.json.data.token //or response.json.data["token"]
response.headers: Response Headers
view response headers
set response headers as variable
Usage example:
response.headers.Server //Or response.headers["Server"]
response.cookies: Response Cookies
view response cookies
Usage example:
response.cookies.liveCookie //Or response.cookies["liveCookie"]