Skip to main content
The rq.response object provides access to all details of the API response in your Requestly scripts. You can use these properties and methods primarily in post-response scripts to process, validate, and extract data from API responses.

Properties and Methods

rq.response.body

The body of the response as a string. Example:

rq.response.bodyEncoding

Tells you how rq.response.body encodes the original response bytes:
  • 'utf8' - the body is the decoded text. This is the case for JSON, XML, HTML, and other text responses.
  • 'base64' - the body is Base64-encoded raw bytes, used for binary responses such as images, PDFs, and archives.
The property is absent on responses saved before this field existed. Treat an absent value as 'utf8'. Example:

rq.response.responseTime

The time taken by the request to complete, in milliseconds. Example:

rq.response.headers

An object holding the response headers. Access a single header with rq.response.headers.get(name) or rq.response.headers.has(name) (both case-insensitive), or get them all as a plain { name: value } object with rq.response.headers.all(). Example:

rq.response.code

The HTTP status code of the response. Example:

rq.response.json()

Parses the response body as JSON and returns it as a JavaScript object. Example:

rq.response.text()

Returns the response body as a plain string. Example:

Common Use Cases

Validate Response Code

Check if the API returned the expected status code:

Extract Data from JSON Response

Parse the response and extract specific fields:

Check Response Time

Monitor API performance:

Extract Authentication Token

Get auth token from response and save it:

Access Response Headers

Validate Response Structure