HTTP
Execute an HTTP(s) connection and fetch the result
Available since 6.0.2 version.
Result expressed as a String (e.g. a JSON or XML result content)
Syntax
Argument detail
uri: URI, expressed as http:// or https:// with or without variables, expressed as :XXX
Settings detail
httpMethod
if specified, it defines the HTTP method: GET, POST, PATCH, PUT, DELETE
replaceVariables (optional) (default is true)
flag used to replace variables within the uri (variables are expressed as :XXX)
contentType (optional)
can be null); if specified, it defines the content type request (e.g. application/json)
requestBody (optional)
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional)
can be null); if specified, it defines the username for a BASIC authentication
pwd (optional)
can be null); if specified, it defines the password for a BASIC authentication
charSet (optional)
can be null); if specified, it defines the char set to use for the request body (req property "Accept-Charset"); if not specified, it is autodefined as "UTF-8"
headers(optional)
can be null); if specified, it defines a collection of attribute-values to pass as request headers; it is expressed as a javascript object: { attr1: value2, attr2: value2, ... }
timeout (optional) (recommended)
optional argument: can be set to null; timeout for the request, expressed in seconds; helpful when the service to invoke could be very slow
additionalSettings (optional)
optional argument: can be set to null; it is a javascript object containing additional settings
requestBody (optional)
if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
dirId (optional)
directory id of file to send
sendFileName (optional)
file name to send
cookie (optional) (default is false)
true if you want use the cookie
log (optional) (default is true)
false if you don't want write the logs
responseWithHeaders (optional) (default is false)
add the headers in response. Example: { headers: { header1: headerValue1, header2: headerValue2...}, response: { ... },
statusCode: 200 }
Example
Execute an HTTP(s) connection and fetch the result
result expressed as a String (e.g. a JSON or XML result content)
Syntax
Details
Argument
Description
uri
URI, expressed as http:// or https:// with or without variables, expressed as :XXX
replaceVariables
flag used to replace variables within the uri (variables are expressed as :XXX)
httpMethod (optional
can be null); if specified, it defines the HTTP method: GET, POST
contentType (optional
can be null); if specified, it defines the content type request (e.g. application/json)
requestBody (optional
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional
can be null); if specified, it defines the username for a BASIC authentication
pwd (optional
can be null); if specified, it defines the password for a BASIC authentication
HTTP response codes included between 200 and 399 are managed as correct answers and the response is sent back through the "json" return variable.
In case of HTTP response codes above or equal to 400, an exception is fired _and the exception content would contain the message sent back by the invoked web service; consequently, it would be better to surround this instruction between try-catch.
Important note: Please pay attention to the URL definition: it must respect the HTTP syntax, which means it cannot contains special characters, such as a space or \n. In case of special characters, you will get an HTTP error when trying to use the URL. In such a scenario, use the encodeURI method:
Examples with errors:
Execute an HTTP(s) connection and fetch the result (with headers)
result expressed as a String (e.g. a JSON or XML result content)
Syntax
Details
Argument
Description
uri
URI, expressed as http:// or https:// with or without variables, expressed as :XXX
replaceVariables
flag used to replace variables within the uri (variables are expressed as :XXX)
httpMethod (optional
can be null); if specified, it defines the HTTP method: GET, POST
contentType (optional
can be null); if specified, it defines the content type request (e.g. application/json)
requestBody (optional
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional
can be null); if specified, it defines the username for a BASIC authentication
pwd (optional
can be null); if specified, it defines the password for a BASIC authentication
charSet (optional
can be null); if specified, it defines the char set to use for the request body (req property "Accept-Charset"); if not specified, it is autodefined as "UTF-8"
headers(optional
can be null); if specified, it defines a collection of attribute-values to pass as request headers; it is expressed as a javascript object: { attr1: value2, attr2: value2, ... }
HTTP response codes included between 200 and 399 are managed as correct answers and the response is sent back throughthe "json" return variable.
In case of HTTP response codes above or equal to 400, an exception is fired and the exception content would contain the message sent back by the invoked web service; consequently, it would be better to surround this instruction between try-catch.
Important note: Please pay attention to the URL definition: it must respect the HTTP syntax, which means it cannot contains special characters, such as a space or \n. In case of special characters, you will get an HTTP error when trying to use the URL. In such a scenario, use the encodeURI method:
Example
Execute an HTTP(s) connection and fetch the result (most flexible version)
result expressed as a String (e.g. a JSON or XML result content)
Syntax
Details
Argument
Description
uri
URI, expressed as http:// or https:// with or without variables, expressed as :XXX
replaceVariables
flag used to replace variables within the uri (variables are expressed as :XXX)
httpMethod (optional
can be null); if specified, it defines the HTTP method: GET, POST
contentType (optional
can be null); if specified, it defines the content type request (e.g. application/json)
requestBody (optional
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional
can be null); if specified, it defines the username for a BASIC authentication
pwd (optional
can be null); if specified, it defines the password for a BASIC authentication
charSet (optional
can be null); if specified, it defines the char set to use for the request body (req property "Accept-Charset"); if not specified, it is autodefined as "UTF-8"
headers(optional
can be null); if specified, it defines a collection of attribute-values to pass as request headers; it is expressed as a javascript object: { attr1: value2, attr2: value2, ... }
timeout
optional argument: can be set to null; timeout for the request, expressed in seconds; helpful when the service to invoke could be very slow
additionalSettings
optional argument: can be set to null; it is a javascript object containing additional settings
Supported attributes by "additionalSettings" argument:
log: true|false - used to turn down the automatic logging of an HTTP request; helpful when you don't want to log credentials passed forward or when you have a large number of requests
enableSNIExtension: true|false - used to customize the SNI settings per single request
HTTP response codes included between 200 and 399 are managed as correct answers and the response is sent back throughthe "json" return variable.
In case of HTTP response codes above or equal to 400, an exception is fired and the exception content would contain the message sent back by the invoked web service; consequently, it would be better to surround this instruction between try-catch.
Important note: Please pay attention to the URL definition: it must respect the HTTP syntax, which means it cannot contains special characters, such as a space or \n. In case of special characters, you will get an HTTP error when trying to use the URL. In such a scenario, use the encodeURI method:
Execute an HTTP(s) connection and fetch the result (binary content)
result expressed as a binary content and store it into the specified file
Syntax
Argument
Description
Details
toFile
absolute path including the file name, related to the local binary file to create and fill in with the result of this HTTP request
uri
URI, expressed as http:// or https:// with or without variables, expressed as :XXX
replaceVariables
flag used to replace variables within the uri (variables are expressed as :XXX)
httpMethod (optional
can be null); if specified, it defines the HTTP method: GET, POST
contentType (optional
can be null); if specified, it defines the content type request (e.g. application/json)
requestBody (optional
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional
can be null); if specified, it defines the username for a BASIC authentication
pwd (optional
can be null); if specified, it defines the password for a BASIC authentication
Fetches the HTTP response, expressed as a binary content and stores in to the specified file.
Important note: Please pay attention to the URL definition: it must respect the HTTP syntax, which means it cannot contains special characters, such as a space or \n. In case of special characters, you will get an HTTP error when trying to use the URL. In such a scenario, use the encodeURI method:
Execute an HTTP(s) connection and fetch the result (binary content) optionally with a body requiest (binary content)
result expressed as a binary content and store it into the specified file
Syntax
Argument
Description
Details
toFile
absolute path including the file name, related to the local binary file to create and fill in with the result of this HTTP request
uri
URI, expressed as http:// or https:// with or without variables, expressed as :XXX
replaceVariables
flag used to replace variables within the uri (variables are expressed as :XXX)
httpMethod (optional
can be null); if specified, it defines the HTTP method: GET, POST
contentType (optional
can be null); if specified, it defines the content type request (e.g. application/json)
requestBody (optional
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional
can be null); if specified, it defines the username for a BASIC authentication
pwd (optional
can be null); if specified, it defines the password for a BASIC authentication
Fetches the HTTP response, expressed as a binary content and stores in to the specified file.
You can pass forward a String based request body as usually (using "requestBody" argument) or pass forward a binary content, using the "settings" argument, where specifying a "fromFile" attribute, filled with an absolute path (including file name) to the file to pass forward, which must be located in the server file system.
Settings can also accept an optional attribute named "headers" containing a javascript object related to the set of request headers to pass forward.
Example
Execute an Alfresco web script
starts with "service/xyz?..." and fetch the result, expresses as a String (e.g. a JSON or XML result content)
Syntax
Details
Argument
Description
uri
last part of the URI to pass to the Alfresco base URL, in order to invoke a webscript, i.e. from the webscript name to required parameters
replaceVariables
flag used to define if :XXX value in the uri must be replaced by Platform defined variables
httpMethod
optional: HTTP method to use: GET, POST, etc.
bodyRequest
optional: body request to pass, expressed as a String
charSet
optional: the request/response charset to use; if not specified, Unicode charset will be used (UTF-8); possible values: UTF-8, Windows-1252
Execute an HTTP(s) connection using NLTM authentication
result expressed as a String (e.g. a JSON or XML result content)
Syntax
Details
Argument
Description
uri
URI, expressed as http:// or https:// with or without variables, expressed as :XXX
contentType (optional)
can be null); if specified, it defines the content type request (e.g. application/json)
httpMethod (optional
can be null); if specified, it defines the HTTP method: GET, POST
requestBody (optional)
can be null); if specified, it defines the request body, expressed as a String (e.g. a JSON or XML content)
user (optional)
Windows username
pwd (optional)
Windows password
workstation
Windows workstation
domain
Windows domain
settings
optional js object; it can contain a few other settings, reported below
HTTP response codes included between 200 and 399 are managed as correct answers and the response is sent back through the "json" return variable.
In case of HTTP response codes above or equal to 400, an exception is fired an the exception content would contain the message sent back by the invoked web service; consequently, it would be better to surround this instruction between try-catch.
The "settings" js object can include the following attributes:
"connectionTimeout: an optional number defining the timeout for the connection
"headers": a js object containing request headers, e.g. required credentials
Example:
Sending back through a server-side js action a response header
When executing a server-side js action, it is possibile to send back not only a JSON response but also response headers, through this method.
Syntax
Details
headerName
name of the response header (e.g. "cookie")
headerValue
the header value
Setting an attribute into the HttpSession through a server-side js action
Within the server-side js action it is also possibile to set attributes into the HttpSession object of the current user session, for example the "username" or "password" values.
Syntax
attributeName
the attribute name to set into the user session (i.e. a specific browser session)
value
the attribute value to set
Last updated