Make DELETE call
The API_DELETE extension sends an HTTP DELETE request to a REST API endpoint from a Virtuoso journey and returns the response body as a journey variable.
This is useful when a test needs to remove a record, clean up test data, revoke an entity, or validate that a delete endpoint accepts the request and completes successfully before the journey continues.
Parameters:
-
urlrequired, the complete API endpoint URL as a string. Query parameters can be included directly in the URL; -
headersoptional, a JSON string containing request headers, for example{"Authorization":"Bearer token"}. When this value is provided, the extension parses it withJSON.parse(headers)before passing it to Axios.
Note: The url input must not be blank. If headers is supplied, it must be valid JSON text because malformed JSON will cause the extension step to fail.
How to apply this to your journey
Use the extension in a journey by calling API_DELETE with the execute command. Pass each value to the matching extension input using as url or as headers.
Note: DELETE endpoints commonly return HTTP 204 No Content. This source code returns only the response body through done(JSON.stringify(data)); it does not return the HTTP status code. Axios treats non-2xx responses as failures and sends them to doneError(e).
execute "API_DELETE" using "https://reqres.in/api/users/2" as url returning $data
assert $data equals ""execute "API_DELETE" using "https://api.example.com/users/2" as url and '{"Authorization":"Bearer YOUR_TOKEN","Content-Type":"application/json"}' as headers returning $dataYou can also store the URL and headers in variables before calling the extension.
execute "API_DELETE" using "$deleteUrl" as url returning $datastore value "https://reqres.in/api/users/2" in $deleteUrl
execute "API_DELETE" using "$deleteUrl" as url returning $dataFor a successful delete request with no response body, the returned value is typically empty. APIs that return a JSON body after deletion will return that JSON body as a stringified value.
Advanced API calls
Some APIs require custom request headers, such as authentication tokens, tenant identifiers, or API-version headers. The API_DELETE 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: Successful DELETE requests often return HTTP 204 No Content, so the returned response body may be empty. The API status code determines whether the request succeeds; non-2xx responses are handled as failures by Axios and passed to doneError.
store value ${'Bearer ' + $token} in $authenticationHeader.Authorization
API_DELETE("https://reqres.in/api/users/2", $authenticationHeader) returning $dataThis extension requires the following resources:
The extension should be configured as:
- Run asynchronously: Yes
- Scope: Global
Limitation: This extension depends on Axios 0.21.1, the configured CDN resource, browser-context network access, and the target API accepting DELETE requests from the execution environment. The request can fail because of CORS restrictions, authentication or token expiry, blocked CDN access, corporate proxy rules, rate limits, API validation, unavailable network routes, or non-2xx HTTP responses. The source returns only data, so a successful 204 No Content response normally gives an empty returned value and the HTTP status code is not available for direct assertions unless the source is extended to return status. Because headers is parsed with JSON.parse, invalid header JSON fails the step before the request is completed. Async extension scripts must call done() or doneError() and complete within Virtuoso's documented 120-second maximum execution window; long-running delete workflows should be handled by an API/backend workflow or split into smaller checks. Cross-browser note: this extension does not inspect the page DOM, but it does rely on browser-style HTTP behavior through Axios and XMLHttpRequest, so CORS, network policy, authentication cookies, and remote-grid or device network configuration can differ across the browser/device configurations used by a plan. Validate it in each configured execution environment rather than assuming one default-browser run represents every target.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 14/01/2021
Resources:
// Last updated: 14/01/2021, 17:44:22 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.delete(
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.