Functions Utility

WebRequest

The WebRequest() function sends an HTTP or HTTPS request to a specified URL using either the GET or POST method and returns the response data.


Syntax:

Qx.WebRequest(URL, Request Type, Data, Certificate, Header Options, Proxy Options, Timeout)
  • In Excel with Quintessence addin versions prior to 25.1, use: WebRequest()
  • In the Quintessence Editor (Studio) using Quintessence language, use: WebRequest()
  • In the Quintessence Editor (Studio) using Python language, use: Qx.WebRequest()
 See parameter descriptions

URLSpecifies the web API endpoint to query
Request TypeDefines the request method. Options are POST or GET.
Data
(optional)
The body content to send with a POST request.
Certificate
(optional)
An encrypted certificate to use for SSL (HTTPS).
Header Options
(optional)
A dictionary of key–value pairs representing headers.
Proxy Options
(optional)
Configuration for the proxy server. Options include:
• System: Uses the system-configured proxy.
• Custom: Uses a custom proxy. The proxy address must be specified.
Timeout
(optional)
Timeout in milliseconds per request.

Remarks:

  • Default parameters:
    • Proxy Options = System
    • Timeout = 100 000ms
  • Authentication, for example Bearer authentication, can be done in the parameter Header Options.

Examples:

> Example 1: GET request with a 5-second timeout


Suppose the URL is http://localhost:808/GetData. The data can be retrieved using the function as follows:

=Qx.WebRequest("http://localhost:808/GetData", "GET",,,,, 5000)

If the data is not retrieved within 5 seconds, a timeout error is returned.

> Example 2: GET request using a proxy server


Suppose the URL is http://localhost:808/GetData and the proxy server 10.1.2.3.4.5:808 requires a username and password. We can define the proxy settings as a string:

Type=Custom;Server=10.1.2.3.4.5:808;UserName=proxy_username;Password=proxy_password

Convert this string into a key–value pair array using the StringToArray function. The data can then be retrieved using the function as follows:

=Qx.WebRequest("http://localhost:808/GetData", "GET",,,, Qx.StringToArray("Type=Custom;Server=10.1.2.3.4.5:808;UserName=proxy_username;Password=proxy_password", ";", "="))
> Example 3: POST request with body and headers


Suppose the URL is http://localhost:808/GetData. The request body is:

{"factor":"price", "date":"2000-01-01"}

The headers are defined as:

content-type#application/json;transaction#00

Convert the header string into a key–value pair array using the StringToArray function. The data can then be retrieved using the function as follows:

=Qx.WebRequest("http://localhost:808/GetData", "POST", '{"factor":"price", "date":"2000-01-01"}', , Qx.StringToArray("content-type#application/json;transaction#00", ";", "#"))
> Example 4: POST request using Bearer authentication


Suppose the URL is http://localhost:808/GetData. The request body is:

{"factor":"price", "date":"2000-01-01"}

The headers are defined as (the 97531 refers to the Bearer token):

Content-Type,application/json;Authorization,Bearer 97531

Convert the header string into a key–value pair array using the StringToArray function. The data can then be retrieved using the function as follows:

=Qx.WebRequest("http://localhost:808/GetData", "POST", '{"factor":"price", "date":"2000-01-01"}', , Qx.StringToArray("Content-Type,application/json;Authorization,Bearer 97531",";",","))