HTTP Request
Verb: httpRequest
Sends an HTTP request to a server, returning the requested information.
Syntax
httpRequest --verb(Nullable<HttpVerb>) --url(String) [--headers(StringDictionary<String>)] [--username(String)] [--password(String)] --formatter(Nullable<HttpFormatter>) [--contentheaders(StringDictionary<String>)] --file(String) --source(String) [--data(String)] [--encoding(Nullable<EncodingType>)] [--mediatype(String)] [--cookiecontainer(CookieContainer)] [--proxy(ProxyVariant)] --noproxy(Boolean) [--timeout(TimeSpan)] (Boolean)=success (String)=value (Numeric)=statusCode (String)=reasonPhrase (StringDictionary<String>)=headers (StringDictionary<String>)=contentHeaders
Inputs
| Script | Designer | Required | AcceptedTypes | Description |
|---|---|---|---|---|
| --verb | Method | Required | HttpVerb | HTTP request method. The available methods are:
|
| --url | URL | Required | Text | Address for submitting the request. |
| --headers | Headers | Optional | String Dictionary<Text> | Request headers with relevant information to the request.
Note: If not specified, the command returns the available headers on the target server.
Default headers:
|
| --username | User Name | Optional | Text | User name required for server authentication, if available. |
| --password | Password | Optional | Text | Password required for server authentication, if available. |
| --formatter | Formatter | Only whenMethod is Post, Put, Patch | HttpFormatter | Body formatter, with available options:
|
| --contentheaders | Content Headers | Optional | String Dictionary<Text> | Headers of body content with information pertinent to the request. |
| --file | File | Only whenFormatter is Bytes | Text | File that should be sent. |
| --source | Body | Only whenFormatter is Text, FormUrlEncoded, Json, Xml, Instance | Text, Http Content | Formatted text that should be sent in the body of the request. |
| --data | Parameters | Optional | Text | Parameters that should be sent in the body of the request. |
| --encoding | Encoding | Optional | EncodingType | Text encoding. Options:
|
| --mediatype | Media Type | Optional | Text | Available when the format is Text. Specifies message body data type.
Example: application/json ou application/xml.
|
| --cookiecontainer | Cookie Container | Optional | Cookie Container | The cookie container stores cookies that are used in the request.
Note: An HTTP cookie is a small piece of data stored in the user's browser. It stores information such as logins and field data. |
| --proxy | Proxy | Optional | Proxy | Receives a proxy variable, which contains the data of the proxy server, username and password. |
| --noproxy | Ignore Global Proxy Configuration | Required | Boolean | When enabled, it ignores the proxy configured in the IBM Robotic Process Automation Studio installer or in the Settings Screen. |
| --timeout | Timeout | Optional | Time Span, Number, Text | Maximum wait time for response.
Note: In case no value is defined for the timeout parameter, the execution uses the timeout defined by the Set Timeout command. If that command is not used on the script, the default timeout is 5 seconds. |
Outputs
| Script | Designer | AcceptedTypes | Description |
|---|---|---|---|
| success | Success | Boolean | If the request was submitted successfully, returns "True", otherwise returns "False". |
| value | Response | Text | HTTP response content coming from server to local machine. |
| statusCode | Status Code | Number | HTTP status code, informing what happened to the HTTP request.
Note: The return ranges from 100 to 500, where: |
| reasonPhrase | Reason Phrase | Text | Phrase sent by the server with the status code.
Note: Status code is the three digits that show the error for the server and browser; The reason phrase is a short description of what this error means for better understanding of users. |
| headers | Headers | String Dictionary<Text> | Response header, with information pertinent to the request in question. |
| contentHeaders | Content Headers | String Dictionary<Text> | HTTP content headers as defined in RFC 2616. |
Example
An HTTP GET request is made to the URL defined in the URL parameter, and its results are shown in the IBM Robotic Process Automation Studio console using the Log Message command.
defVar --name status --type Numeric
defVar --name reasonPhrase --type String
defVar --name message --type StringDictionary --innertype String
defVar --name success --type Boolean
defVar --name response --type String
defVar --name header --type StringDictionary --innertype String
httpRequest --verb "Get" --url "https://jsonplaceholder.typicode.com/posts" success=success response=value status=statusCode reasonPhrase=reasonPhrase header=headers message=contentHeaders
logMessage --message "Success: ${success}\r\n\r\nResponse: ${response}\r\n\r\nStatus: ${status}\r\n\r\nReason Phrase: ${reasonPhrase}\r\n\r\nHeader: ${header}\r\n\r\nMessage: ${message}" --type "Info"
// Make an HTTP GET request at a Fake API website and returns results in the IBM Robotic Process Automation Studio console.