The API_GET extension sends a GET request to a REST API endpoint and returns the response body as a JSON string that can be stored in a Virtuoso variable.
This is useful when a journey needs to retrieve setup data, validate an API response, or compare UI behavior against data returned by a backend endpoint before continuing with browser-based checks.
Parameters:
-
urlrequired, a string containing the full API URL to call. Query parameters can be included directly in the URL, for examplehttps://reqres.in/api/users?page=2; -
headersoptional, a JSON string containing request headers to pass to Axios. Leave it blank when no custom headers are required. When supplied, it must be valid JSON, for example{"Authorization":"Bearer token"}.
Note: The extension returns JSON.stringify(data), so the output is stored as a JSON string. Use Virtuoso variable assertions against the returned data structure only after the response has been captured in a variable.
How to apply this to your journey
Use the extension in a journey by calling API_GET with the execute command. Pass the URL using as url, and pass request headers using as headers only when your API requires them.
Note: This extension is asynchronous and must be configured with Run asynchronously: Yes. A successful request calls done() with the response body, while failures are returned through doneError() and fail the extension step.
execute "API_GET" using "https://reqres.in/api/users?page=2" as url returning $dataexecute "API_GET" using "https://api.example.com/users" as url and '{"Authorization":"Bearer token"}' as headers returning $dataYou can also pass the URL and headers from variables when the endpoint or token changes between environments.
execute "API_GET" using "$apiUrl" as url and "$requestHeaders" as headers returning $datastore value "https://reqres.in/api/users?page=2" in $apiUrl
store value '{"Accept":"application/json"}' in $requestHeaders
execute "API_GET" using "$apiUrl" as url and "$requestHeaders" as headers returning $data
assert $data.page equals "2"Advanced API calls
Some APIs require custom request headers, such as authentication tokens, content negotiation headers, tenant identifiers, or API-version headers. The API_GET extension supports this through the optional headers input. Pass headers as a valid JSON string or as a Virtuoso variable that resolves to a JSON object/string.
Note: Header names must match what the target API expects. For bearer-token authentication, build an Authorization header and pass it as the optional headers parameter.
store value ${'Bearer ' + $token} in $authenticationHeader.Authorization
API_GET("https://reqres.in/api/users?page=2", $authenticationHeader) returning $data
assert $data.page equals "2"Example output from the sample request can look like this. The actual response depends on the API endpoint being called.
{
"page": 2,
"per_page": 6,
"total": 12,
"total_pages": 2,
"data": []
}This extension requires the following resources:
The extension should be configured as:
- Run asynchronously: Yes
- Scope: Global
Limitation: This extension depends on the external Axios resource, the browser/device network context used by the Virtuoso journey, and the target API accepting browser-originated GET requests. Because Axios uses browser HTTP/XHR behavior in this context, requests can fail due to CORS restrictions, expired or invalid authentication headers, malformed header JSON, blocked CDN access, proxy/VPN restrictions, API rate limits, unavailable endpoints, or backend validation changes. It does not define a custom request timeout, retry policy, response filtering, or secret masking, so long-running calls must complete within Virtuoso's documented 120-second maximum execution window, and sensitive values passed in headers or returned by the API should be handled carefully because they may be visible in journey variables, logs, or failure details. Cross-browser note: The extension does not intentionally query or mutate the page DOM, but it does perform a browser-context network request through Axios. Validate it in each browser/device configuration used by your plans, especially Safari, Firefox, Edge, iOS, Android, or remote-grid executions, because network behavior, CORS enforcement, corporate proxy routing, and third-party API access can differ from the default execution environment.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 14/01/2021, 17:44:34 UTC
Resources:
// Last updated: 14/01/2021, 17:44:34 UTC
// Resources:
// https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js
const makeRequest = async (url, headers = '') => {
try {
const { data } = await axios.get(
url,
headers ? { headers: JSON.parse(headers) } : {},
)
done(JSON.stringify(data))
} catch (e) {
doneError(e)
}
}
if (!url) {
throw new Error('URL parameter is missing')
}
makeRequest(url, headers)
Comments
0 comments
Please sign in to leave a comment.