HTTP Request

Sends an HTTP request to a server, returning the requested information.

Command availability: IBM Robotic Process Automation as a Service and IBM RPA on premises

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in RPA Studio's Script mode.

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

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Method verb Required HttpVerb The HTTP request method.

See the verb parameter options.
URL url Required Text The request target URL.
Headers headers Optional String Dictionary<Text> The request headers used to provide additional information about the request content.
User Name username Optional Text Network credential user.
Password password Optional Text Network credential password.
Formatter formatter Required when Method is post, put, patch HttpFormatter The text format.

See the formatter parameter options.
Content Headers contentheaders Optional String Dictionary<Text> Headers of body content with information pertinent to the request.
File file Required when the Formatter parameter is enabled Text File to be sent.
Body source Optional Text, Http Content Formatted text to be sent in the body of the request.
Parameters data Optional Text Parameters to be sent in the body of the request.
Encoding encoding Optional EncodingType The text encoding.

See the encoding parameter options.
Media Type mediatype Optional Text Media type of the text.
Cookie Container cookiecontainer Optional Cookie Container The cookie container is used to store the request's cookies, which can be used in subsequent requests.

See the cookiecontainer parameter for more details.
Proxy proxy Optional Proxy Proxy used on the request.
Ignore Global Proxy Configuration noproxy Required Boolean Enable to ignore the proxy set in the IBM RPA installation or in the Configuration > Proxy page.
Timeout timeout Optional Time Span, Number, Text Maximum response time. The default time is 5 seconds.

verb parameter options

The following table displays the options available for the verb input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.

Designer mode label Script mode name Description
Get Get Returns any information that is identified in the requested URL. You can also specify the following conditions in the request header.
- If-Modified-Since
- If-Unmodified-Since
- If-Match
- If-None-Match
- If-Range
Delete Delete Requests the origin server to delete the resource identified by the URL.Requests the origin server to delete the resource identified by the URL. Responses for this method cannot be cached. If the request is cached and the URL identifies one or more cached entities simultaneously, these entities become obsolete. Keep in mind that this action can be interrupted by the server.
Head Head Retrieves information similarly to the Get method, but it only receives meta-information that can be stored instead of the message body. The response metadata are identical to those obtained by using the Get method.
Options Options Requests information about communication options for the target server.
Patch Patch Applies partial modifications to a resource on the target server.
Post Post Sends data to the target server.
Put Put Creates or replaces a resource on the target server.

formatter parameter options

The following table displays the options available for the formatter input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.

Designer mode label Script mode name
Operating System Default Default
UTF8 UTF8
UTF7 UTF7
UTF32 UTF32
Unicode Unicode
ASCII ASCII
Big Endian Unicode BigEndianUnicode
Automatic Auto

encoding parameter options

The following table displays the options available for the enconding input parameter. The table shows the options available when working in Script mode and the equivalent label in the Designer mode.

Designer mode label Script mode name
Bytes Bytes
Form URL encoded FormUrlEncoded
Instance Instance
Json Json
Text Text
XML XML

Output parameters

Designer mode label Script mode name Accepted variable types Description
Success success Boolean Returns true if the request is successfully submitted and false otherwise.
Response value Text The request response content.
Status Code statusCode Number HTTP response status codes indicate whether a specific HTTP request has been successfully completed. See the HTTP responses for more details.
Reason Phrase reasonPhrase Text Short description of the status code.
Headers headers String Dictionary<Text> Response header, with information pertinent to the request in question.
Content Headers contentHeaders String Dictionary<Text> HTTP content headers as defined in RFC 2616 🡥.

HTTP responses

The following table displays the responses to the HTTP request:

Response code Description
100 Information responses.
200 Sucessful responses.
300 Redirection messages.
400 Request errors.
500 Errors on the server.

Example

The following code example demonstrates how to make an HTTP request to a fake API using the GET Method and logging the response in the IBM RPA Studio console using the Log Message (logMessage) command.

defVar --name success --type Boolean
defVar --name response --type String
defVar --name statusCode --type Numeric
defVar --name reason --type String
defVar --name headers --type StringDictionary --innertype String
defVar --name contentHeaders --type StringDictionary --innertype String
httpRequest --verb "Get" --url "https://jsonplaceholder.typicode.com/posts" --cookiecontainer  success=success response=value statusCode=statusCode reason=reasonPhrase headers=headers contentHeaders=contentHeaders
logMessage --message "Success: ${success}\r\n\r\nResponse: ${response}\r\n\r\nStatus: ${statusCode}\r\n\r\nReason Phrase: ${reason}\r\n\r\nHeader: ${headers}\r\n\r\nContent headers: ${contentHeaders}" --type "Info"

Limitations

The Body parameter only accepts HTTP content variables in cases where the Formatter parameter is set to Instance.