SOAP Request
SOAP is a protocol created to facilitate remote calls via the Internet, allowing two programs to communicate.
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
A SOAP (Simple Object Access Protocol) is a way to share information from the sending application to the receiving application, usually, by using HTTP session. The information sharing is transmitted by using XML (eXtensible Markup Language) format. You can send a SOAP request according to your needs, by filling fields, such as: URL, Action, Source, among others. After that, the application that received the request returns the content related to the request made.
Limitations
If you use the Map XML (mapXml
) command to get the content of your request, this command might not work properly.
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.
soapRequest --url(String) [--headers(StringDictionary<String>)] [--username(String)] [--password(String)] --action(String) --source(String) [--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 |
---|---|---|---|---|
URL | url |
Required |
Text |
The target server's address. |
Headers | headers |
Optional |
String Dictionary<Text> |
Headers calls for information about the headers of the request, such as host or cookies, for example. |
User Name | username |
Optional |
Text |
Network credential user. Parameter used for proxy authentication. |
Password | password |
Optional |
Text |
Network credential password. Parameter used for proxy authentication. |
Action | action |
Required |
Text |
Action that you want to run in the request. For more information, see The SOAPAction HTTP Header Field 🡥. |
Source | source |
Required |
Text |
The SOAP content for the request. |
Ignore Global Proxy Configuration | noproxy |
Optional |
Boolean |
Enable to ignore the proxy set in the IBM RPA installation or in the IBM RPA Client: Proxy 🡥 page. |
Timeout | timeout |
Optional |
Time Span, Number, Text |
Maximum response time. The default time is 5 seconds. |
Output parameters
Designer mode | Script mode | Accepted variable types | Description |
---|---|---|---|
Success | success |
Boolean |
Returns True , if the request was sent successfully, or False , otherwise. |
Response | value |
Text |
Returns the contents of the SOAP response from the server to the local machine. |
Status Code | statusCode |
Number |
Returns the HTTP status code, informing what happened to the SOAP request. See the statusCode parameter options for more details. |
Reason Phrase | reasonPhrase |
Text |
Phrase sent by the server with the status code. The status code corresponds to the three digits that show the type of error that occurred; the reason sentence is a short description of what this error means. |
Headers | headers |
String Dictionary<Text> |
Returns the response header with information relevant to the requisition. |
Message Headers | contentHeaders |
String Dictionary<Text> |
Returns the SOAP content headers, as defined in RFC 2616 🡥. |
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 descriptions. 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
This command sends a SOAP-type message protocol to obtain information about a country, such as its flag, Iso Code, Capital city, and others.
defVar --name soapRequestSent --type Boolean
defVar --name soapResponseBody --type String
defVar --name soapResponseStatusCode --type Numeric
defVar --name countryIsoCode --type String
defVar --name countryName --type String
defVar --name countryCapitalCity --type String
defVar --name countryPhoneCode --type String
defVar --name countryContinentalCode --type String
defVar --name countryCurrencyIsoCode --type String
defVar --name countryFlagUrl --type String
defVar --name countryLanguages --type String
defVar --name sCountryISOCodeToSendOnSoapRequest --type String --value BR
defVar --name target_URL --type String --value "http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso"
defVar --name SOAP_ACTION --type String --value "http://www.oorsprong.org/websamples.countryinfo/CountryInfoServiceSoapType/FullCountryInfoRequest"
defVar --name languageNodesCount --type Numeric
defVar --name REGEX_LANGUAGE_NODES --type String --value "\\<m\\:tLanguage\\>(.+?)\\<\\/m\\:tLanguage\\>"
defVar --name REGEX_SISOCODE_NODES --type String --value "\\<m\\:sISOCode\\>(.+?)\\<\\/m\\:sISOCode\\>"
defVar --name occurenceNumber --type Numeric
defVar --name REGEX_LANGUAGES_NODES --type String --value "\\<m\\:Languages\\>(.+?)\\<\\/m\\:Languages\\>"
defVar --name languagesNodes --type String
defVar --name languageNode --type String
defVar --name languageIsoCode --type String
defVar --name countryLanguageIsoCodes --type List --innertype String
defVar --name REGEX_NAME_NODES --type String --value "\\<m\\:sName\\>(.+?)\\<\\/m\\:sName\\>"
defVar --name REGEX_CAPITALCITY_NODES --type String --value "\\<m\\:sCapitalCity\\>(.+?)\\<\\/m\\:sCapitalCity\\>"
defVar --name REGEX_COUNTRYFLAG_NODES --type String --value "\\<m\\:sCountryFlag\\>(.+?)\\<\\/m\\:sCountryFlag\\>"
soapRequest --url "${target_URL}" --action "${SOAP_ACTION}" --source "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://www.oorsprong.org/websamples.countryinfo\">\r\n <soapenv:Header/>\r\n <soapenv:Body>\r\n <web:FullCountryInfo>\r\n <web:sCountryISOCode>${sCountryISOCodeToSendOnSoapRequest}</web:sCountryISOCode>\r\n </web:FullCountryInfo>\r\n </soapenv:Body>\r\n</soapenv:Envelope>" soapRequestSent=success soapResponseBody=value soapResponseStatusCode=statusCode
logMessage --message "soapResponseStatusCode=${soapResponseStatusCode}\r\nsoapResponseBody=${soapResponseBody}" --type "Info"
mapXml --xml "${soapResponseBody}" --mappings "{\"//*[local-name()=\'sISOCode\']\":\"${countryIsoCode}\",\"//*[local-name()=\'sName\']\":\"${countryName}\",\"//*[local-name()=\'sCapitalCity\']\":\"${countryCapitalCity}\",\"//*[local-name()=\'sPhoneCode\']\":\"${countryPhoneCode}\",\"//*[local-name()=\'sContinentCode\']\":\"${countryContinentalCode}\",\"//*[local-name()=\'sCurrencyISOCode\']\":\"${countryCurrencyIsoCode}\",\"//*[local-name()=\'sCountryFlag\']\":\"${countryFlagUrl}\",\"//*[local-name()=\'Languages\']\":\"${countryLanguages}\"}"
//Notice that there are some limitations here. Either mapXml returns more than one node or it can't return the node. To work around these limitations, you need to use RegEx.
//Known limitations:
// (1) If XML has namespaces and nodes with the same name, you can't select an specific node. Must use regex to get specific node.
// (2) If XML has namespaces and nodes with children nodes, you can't get all children by targeting parent. Must use regex to parse.
logMessage --message "countryIsoCode=${countryIsoCode}\ncountryName=${countryName}\ncountryCapitalCity=${countryCapitalCity}\ncountryLanguageIsoCodes=${countryLanguages}\r\ncountryFlagUrl=${countryFlagUrl}" --type "Info"
//These next two regexes are straightforward. Since we know the response's structure, we can get the strings directly.
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_SISOCODE_NODES}" --regexOptions "0" --groupnumber 1 countryIsoCode=value
logMessage --message "countryIsoCode=${countryIsoCode}" --type "Info"
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_NAME_NODES}" --regexOptions "0" --groupnumber 1 countryName=value
logMessage --message "countryName=${countryName}" --type "Info"
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_CAPITALCITY_NODES}" --regexOptions "Singleline" --groupnumber 1 countryCapitalCity=value
logMessage --message "countryCapitalCity=${countryCapitalCity}" --type "Info"
//A comes the magic: a node that can have multiple child nodes. To parse such node, you must count its children, get them, and then loop through all of them.
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_LANGUAGES_NODES}" --regexOptions "Singleline" --groupnumber 1 languagesNodes=value
countTextOccurrences --text "${languagesNodes}" --useRegex --regexPattern "${REGEX_LANGUAGE_NODES}" --regexOptions "Singleline" --startindex 1 languageNodesCount=value
for --variable ${occurenceNumber} --from 1 --to ${languageNodesCount} --step 1
getRegex --text "${languagesNodes}" --regexPattern "${REGEX_LANGUAGE_NODES}" --regexOptions "Singleline" --groupnumber 1 --getbyindex --occurrenceindex ${occurenceNumber} languageNode=value
getRegex --text "${languageNode}" --regexPattern "${REGEX_SISOCODE_NODES}" --regexOptions "0" --groupnumber 1 languageIsoCode=value
add --collection "${countryLanguageIsoCodes}" --value "${languageIsoCode}"
next
logMessage --message "countryLanguageIsoCodes=${countryLanguageIsoCodes}" --type "Info"
getRegex --text "${soapResponseBody}" --regexPattern "${REGEX_COUNTRYFLAG_NODES}" --regexOptions "Singleline" --groupnumber 1 countryFlagUrl=value
logMessage --message "countryFlagURL=${countryFlagUrl}" --type "Info"
webStart --name browser --type "Chrome"
webNavigate --url "${countryFlagUrl}"
webClose --name browser --leavebrowseropen