HTTP Request

Sends an HTTP request to a server and returns the requested resource.

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

Description

This command sends an HTTP request to a server using the specified methods, headers and content headers.

HTTP (Hypertext Transfer Protocol) is a protocol that establishes a communication between a client and a server. You deal with HTTP protocol when you open your browser, and do a search, for example.

By typing anything and click enter, your browser is the client that is sending a message for a server. This message contains the information that you are searching for.

Limitations

  • This command uses HTTP/1.1 only.

  • This command creates the following standard headers:

    Accept: application/JSON, application/bson, text/xml
    Accept-Encoding: gzip, deflate
    User-Agent: <DEPENDS_ON_HOSTNAME_AND_OS_BUILD>
    Content-Type: <DEPENDS_ON_FORMATTER>
    Host: <DEPENDS_ON_URL>
    Content-Length: <DEPENDS_ON_BODY>
    Expect: 100-continue
    

Example of <DEPENDS_ON_HOSTNAME_AND_OS_BUILD>: Studio/23.0.0.0 (Microsoft Windows NT 6.2.9200.0; Win32NT; x64) IBMRoboticProcessAutomation/23.0.0.0 (LAPTOP-XPT2OW1C; Enterprise)

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 IBM 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 IBM 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 page (https://localhost:8099/web/en-US/ibmrpaclient) in the Proxy tab.
Timeout timeout Optional Time Span, Number, Text Maximum response time. The default time is 5 seconds.

verb parameter options

When this command sends the request to the server, it must specify a method so that you get the responses that you are waiting for. The following table shows all methods available in IBM RPA.

Designer mode label Script mode name Required
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. Responses to 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 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

encoding parameter options

The following table displays the options available for the encoding 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 Big Endian Unicode
Automatic Auto

cookiecontainer parameter options

The Cookie container parameter passes and updates stored cookies to subsequent requests. To use it, you must create a Cookie Container variable.

The Cookie Container variable stores sets of cookies that are collected by the website in the HTTP request. When the Cookie Container variable is used in subsequent Http Request command, it sends all cookies collected to this request, even from previous requests.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Success Success Boolean Returns True if the request is successfully submitted, or False, otherwise.
Response value Text Returns the request response content.
Status Code statusCode Number Indicates if a specific HTTP request has been successfully completed. See the statusCode parameter options for more details.
Reason Phrase reasonPhrase Text Returns a short description of the status code.
Headers headers String Dictionary<Text> Returns the response header with information pertinent to the request.
Content Headers contentHeaders String Dictionary<Text> Returns the headers of the body content with information pertinent to the request. For more information, see Message Headers 🡥.

statusCode parameter options

The server interprets the HTTP request and sends a response to the client. This response contains a code to indicate the status request, in which the first number indicates the class of the response.

In the following table, you find the response code and their description. See Status code 🡥 for details.

Response code Description
1xx Information responses.
2xx Successful responses.
3xx Redirection messages.
4xx Request errors.
5xx Errors on the server.

Example

The following code example demonstrates how to send HTTP requests to integrate with a temporary email provider, by creating and deleting a temporary email in Temp Mail API. See Integrating IBM RPA with external APIs for details.

defVar --name password --type String
defVar --name accountSuccess --type Boolean
defVar --name accountJsonResponse --type String
defVar --name accountStatusCode --type Numeric
defVar --name accountReasonPhrase --type String
defVar --name domainRequestSuccess --type Boolean
defVar --name domainJsonBodyResponse --type String
defVar --name domainRequestCode --type Numeric
defVar --name avaliableDomainsDataTable --type DataTable
defVar --name domainUsed --type String
defVar --name tokenRequestSuccess --type Boolean
defVar --name tokenJsonBodyResponse --type String
defVar --name tokenRequestCode --type Numeric
defVar --name connectionToken --type String
defVar --name requestHeader --type StringDictionary --innertype String
defVar --name emailId --type String
defVar --name deleteRequestSuccess --type Boolean
defVar --name deleteJsonBodyResponse --type String
defVar --name deleteRequestCode --type Numeric
defVar --name randomText --type String
defVar --name deleteReasonPhrase --type String
defVar --name domainReasonPhrase --type String
defVar --name tokenReasonPhrase --type String
//Get domain
httpRequest --verb "Get" --url "https://api.mail.tm/domains" domainRequestSuccess=success domainJsonBodyResponse=value domainRequestCode=statusCode domainReasonPhrase=reasonPhrase
logMessage --message "Success: ${domainRequestSuccess} - ${domainRequestCode}: ${domainReasonPhrase}\r\n\r\nDomains available\r\n${domainJsonBodyResponse}\r\n___________________________________________________________________" --type "Info"
jsonToTable --json "${domainJsonBodyResponse}" --jsonPath "$" avaliableDomainsDataTable=value
mapTableRow --dataTable ${avaliableDomainsDataTable} --row 1 --mappings "name=domain=${domainUsed}"
//Create account with POST
createRandomText --uselowercaseletters  --minimumlength 5 --maximumlength 7 randomText=value
createRandomText --useuppercaseletters  --uselowercaseletters  --usedigits  --usesymbols  --minimumlength 8 --maximumlength 10 password=value
httpRequest --verb "Post" --url "https://api.mail.tm/accounts" --formatter "Json" --source "{\r\n  \"address\": \"${randomText}@${domainUsed}\",\r\n  \"password\": \"${password}\"\r\n}" accountSuccess=success accountJsonResponse=value accountStatusCode=statusCode accountReasonPhrase=reasonPhrase
//Get email ID
mapJson --json "${accountJsonResponse}" --mappings "id=${emailId}"
logMessage --message "Success: ${accountSuccess} - ${accountStatusCode}: ${accountReasonPhrase}\r\n\r\nAccount: ${accountJsonResponse}\r\n\r\nEmail ID: ${emailId}\r\n\r\n___________________________________________________________________\r\n" --type "Info"
//Create and mapped the token POST
httpRequest --verb "Post" --url "https://api.mail.tm/token" --formatter "Json" --source "{\r\n  \"address\": \"${randomText}@${domainUsed}\",\r\n  \"password\": \"${password}\"\r\n}" tokenRequestSuccess=success tokenJsonBodyResponse=value tokenRequestCode=statusCode tokenReasonPhrase=reasonPhrase
mapJson --json "${tokenJsonBodyResponse}" --mappings "token=${connectionToken}"
//Here the token is added to the dictionary used as header
strDictAdd --key Authorization --value "Bearer ${connectionToken}" --dictionary ${requestHeader}
logMessage --message "Success: ${tokenRequestSuccess} - ${tokenRequestCode}: ${tokenReasonPhrase}\r\n\r\nToken created: ${tokenJsonBodyResponse}\r\n___________________________________________________________________" --type "Info"
//Delete email account
httpRequest --verb "Delete" --url "https://api.mail.tm/accounts/${emailId}?id=${emailId}" --headers ${requestHeader} deleteRequestSuccess=success deleteJsonBodyResponse=value deleteRequestCode=statusCode deleteReasonPhrase=reasonPhrase
logMessage --message "Success: ${deleteRequestSuccess} - ${deleteRequestCode}: ${deleteReasonPhrase}\r\n___________________________________________________________________" --type "Info"