Request
Performs HTTP requests.
Performs a URL request and returns the response in an appropriate format.
Properties
Section titled “Properties”allowInsecureRequest
Section titled “allowInsecureRequest”Allow the request even if it is deemed insecure.
allowInsecureRequest: boolBy default Scriptable will attempt to reject requests that are deemed insecure.
As an example, Scriptable will reject communicating with a server that has an invalid certificate. Such servers might be malicious and may put confidentional information at risk. By enabling this setting, those requests will be allowed.
Enable this setting at your own risk.
Body to send with the request.
body: anyThe body will be send along the request. While this property can be any value, currently only strings and Data is supported.
Be aware that this property is ignored if you convert the request to a multipart request using addParameterToMultipart,
addFileToMultipart or addFileDataToMultipart.
headers
Section titled “headers”HTTP headers to send with the request.
headers: {string: string}Key value pairs where the key is the name of an HTTP header and the value will be sent as the value for the HTTP header.
method
Section titled “method”HTTP method used for the request.
method: stringSpecifies the HTTP method to use when sending the request. The default is to send the request using the GET HTTP method.
onRedirect
Section titled “onRedirect”Function called upon redirect.
onRedirect: fn(Request) -> RequestThe function determines how redirects should be handled. By default redirects are allowed. When invoked the function is supplied with the request that we’re about to redirect to. The function can return the request to continue redirecting or it can return another request to redirect to. Returning null will stop the redirect. Note that onRedirect will only be invoked on the initial request. Consecutive redirects should be handled on the initial request.
response
Section titled “response”Response of the request.
response: {string: any}The response is not populated until the request has been completed. The response is an object that looks like the following example.
{ "url": "https://example.com/", "statusCode": 200 "mimeType": "application/json", "textEncodingName": "utf-8", "headers": { "Content-Type": "application/json;charset=utf-8", "Content-Length": "17671" }, "cookies": [{ "path": "/", "httpOnly": true, "domain": "www.example.com", "sessionOnly": true, "name": "JSESSIONID", "value": "7616271F4878CFD05182D20C45F4CEB3" }]}Read-only.
timeoutInterval
Section titled “timeoutInterval”Timeout interval of the request.
timeoutInterval: numberIf a request remains idle for longer than the timeout interval, the request is considered timed out.
The timeout interval is measured in seconds and defaults to 60 seconds.
URL to send request to.
url: stringMethods
Section titled “Methods”
new Request(url)
Section titled “new Request(url)”Constructs a request.
new Request(url: string)Constructs a new request that will be sent to the provided URL. The request is not sent until an appropriate load method is called, e.g. loadImage for downloading and interpreting the response as an image.
Parameters
Section titled “Parameters”url string
URL to send request to.
addFileDataToMultipart(data, mimeType, name, filename)
Section titled “addFileDataToMultipart(data, mimeType, name, filename)”Adds a file to a multipart request.
addFileDataToMultipart(data: Data, mimeType: string, name: string, filename: string)Converts the request to a multipart request and adds the file to the request. Be aware that the body property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.
Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to “multipart/form-data”.
Parameters
Section titled “Parameters”data Data
File data to add.
mimeType string
MIME type of the file to add.
name string
Name of the parameter which holds the file.
filename string
Name of the file.
addFileToMultipart(filePath, name, filename)
Section titled “addFileToMultipart(filePath, name, filename)”Adds a file to a multipart request.
addFileToMultipart(filePath: string, name: string, filename: string)Converts the request to a multipart request and adds the file to the request. The function will automatically determine the MIME type of the file as well as the filename. Be aware that the body property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.
Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to “multipart/form-data”.
Parameters
Section titled “Parameters”filePath string
Path of the file to add.
name string
Name of the parameter which holds the file.
filename string
Optional name of the uploaded file.
addImageToMultipart(image, name, filename)
Section titled “addImageToMultipart(image, name, filename)”Adds an image to a multipart request.
addImageToMultipart(image: Image, name: string, filename: string)Converts the request to a multipart request and adds the image to the request. The function will automatically determine the MIME type of the file Be aware that the body property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.
Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to “multipart/form-data”.
Parameters
Section titled “Parameters”image Image
Image to add.
name string
Name of the parameter which holds the file.
filename string
Optional name of the uploaded file.
addParameterToMultipart(name, value)
Section titled “addParameterToMultipart(name, value)”Adds a parameter to a multipart request.
addParameterToMultipart(name: string, value: string)Converts the request to a multipart request and adds a parameter with the specified name and value. Be aware that the body property on the request is ignored for multipart requests as parameters and files added to the request constitutes the body.
Calling this function will make the request a multipart request. When the request is send, the content type will automatically be set to “multipart/form-data”.
Parameters
Section titled “Parameters”name string
Name of the parameter.
value string
Value of the parameter.
load()
Section titled “load()”Sends request.
load(): Promise<Data>Call to send the configured request to the specified URL. The raw response is provided when the returned promise is fulfilled.
Return value
Section titled “Return value”Promise<Data>
Promise that provides the response as data when fulfilled.
loadImage()
Section titled “loadImage()”Sends request and parses response as an image.
loadImage(): Promise<Image>Call to send the configured request to the specified URL. The response is expected to be an image.
Return value
Section titled “Return value”Promise<Image>
Promise that provides the response as an image.
loadJSON()
Section titled “loadJSON()”Sends request and parses response as JSON.
loadJSON(): Promise<any>Call to send the configured request to the specified URL. The response is expected to be a valid JSON string and is parsed into an object.
Return value
Section titled “Return value”Promise<any>
Promise that provides the response as an object when fulfilled.
loadString()
Section titled “loadString()”Sends request and parses response as a string.
loadString(): Promise<string>Call to send the configured request to the specified URL. The response is parsed to a string and provided when the returned promise is fulfilled.
Return value
Section titled “Return value”Promise<string>
Promise that provides the response as a string when fulfilled.