Create HTTP Content

Creates a variable that stores the contents and headers of one or more HTTP messages.

Command availability: IBM RPA SaaS and IBM RPA on premises

Description

HTTP (Hypertext Transfer Protocol) is a protocol that establishes a communication between a client and a server. See HTTP Request for details.

Syntax

IBM RPA has their proprietary script language that is 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.

createHttpContent --formattype(Nullable<HttpFormatter>) [--boundary(String)] [--contentheader(String)] [--body(String)] [--parameters(String)] [--encoding(Nullable<EncodingType>)] [--mediatype(String)] --file(String) [--contentlist(String)] (HttpContent)=value

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
Formatter formattype Required HttpFormatter The text format. See the formattype parameter options for details.
Boundary boundary Optional Text Text used to separate different HTTP messages.
Content Headers contentheader Optional Text Content headers with information from the request.
Body body Optional Text Content of the HTTP request body. Body and Parameters are inputs referencing to the same value.
Parameters parameters Optional Text Parameters that should be sent in the body of the request. Parameters and Body are inputs referencing to the same value.
Encoding encoding Optional EncodingType Text encoding format to be used for the request. See the encoding parameter options for details.
Media Type mediatype Optional Text The format of the request's body. For example, text/plain.
File file Only when Formatter is Bytes Text File to send.
Contents contentlist Optional Text Mappings of HTTP messages to be used. In the Parameter field, enter the element to be mapped. In the Value field, enter the variable that receives the content of the mapped element.

formattype parameter options

The following table displays the options available for the formattype 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
JSON Json
Multipart Multipart
Text Text
XML Xml

encoding parameter options

The following table displays the options available for the encoding parameter options. 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
ASCII ASCII
Big Endian Unicode Big Endian Unicode
Operating System Default Default
Unicode Unicode
UTF32 UTF32
UTF7 UTF7
UTF8 UTF8

Output parameters

Designer mode Script mode Accepted variable types Description
Content value Http Content Returns the content of the HTTP request.

Example

The following code example creates different HTTP messages, storing all of them in one variable and executes POST method request, instancing different messages to perform the requests.

defVar --name content --type HttpContent
defVar --name multicontentvar --type HttpContent
defVar --name content2 --type HttpContent
defVar --name content1 --type HttpContent
defVar --name content3 --type HttpContent
defVar --name content4 --type HttpContent
defVar --name success --type Boolean
defVar --name response --type String
createHttpContent --formattype "Json" --contentheader "MyHeader1: test port:8080" --body "{\"tests\":\r\n    {\r\n        \"test1\":\"First\",\r\n        \"test2\":\"Second\"\r\n    }\r\n}" content=value
createHttpContent --formattype "Json" --contentheader "MyHeader2: test port:8080" --parameters "test1=First,test2=Second" content1=value
createHttpContent --formattype "Text" --contentheader "MyHeader3: test port:80" --body "<html>\r\n<body>\r\n</body>\r\n</html>" --encoding "Default" --mediatype "application/html" content2=value
createHttpContent --formattype "Xml" --contentheader "MyHeader5: test port:8080" --body "<note>\r\n<from>Anonymous</from>\r\n<to>You</to>\r\n<messsage>We need more coffee.</message>\r\n</note>\r\n" content3=value
createHttpContent --formattype "Xml" --contentheader "MyHeader6: test port:8080" --body "\r\n" --parameters "<from>=Anonymous,<to>=You,<messsage>=We need more coffee." content4=value
createHttpContent --formattype "Multipart" --boundary asdfasf --contentheader "Warning: test warning" --contentlist "content1=${content},content2=${content1},content3=${content2},content4=${content3},content5=${content4}" multicontentvar=value
httpRequest --verb "Post" --url "https://httpbin.org/post" --formatter "Instance" --source "${multicontentvar}" --noproxy  success=success response=value
logMessage --message "Success: ${success}\r\nResponse: ${response}" --type "Info"