REST package guide
Build URLs and send HTTP requests with authentication, row inputs and files.
Version 3.0.7. Installed versions can differ. Examples are illustrative and not tested. Packages.
Prerequisites
Install this package on the Device that runs the automation, with a compatible Mercury runtime. The Run account needs network access, read access to upload files and certificates, and write access to download folders. Relative paths start in the Run working folder. The URL helpers (Build, Decode, Encode, Get query parameters, Get URL hostname, Get URL protocol) only work on text and need no network.
The examples use made-up addresses. Set up your own test service that returns the example status and content; the package does not include one. Do not send passwords or tokens to a service you do not trust. A field that holds only one variable needs the right type: a Dictionary for query parameters, a List for Windows hosts and String variables for secrets. To put a Number into text, write $count|string$.
Address rules.
- Only
httpandhttpsaddresses work. - If any address found for the target is on this PC or inside your network, the request is blocked unless you turn on Allow an address inside the network. Each redirect is checked again. On a direct connection, the step connects to the address it checked. Through a proxy, the check uses this PC's name lookup, but the proxy connects on its own and can look up the name again.
- A custom proxy on this PC or inside your network needs the same switch. The system proxy is the Device setting and is used as set.
- Allow an address inside the network does not turn off certificate checks.
Sign-in rules.
- Basic and Bearer need HTTPS. Over HTTP they work only when every address of the target is on this PC or in a private IPv4 range (RFC 1918), with both Allow an address inside the network and Allow an insecure connection on. IPv6 unique-local and link-local addresses do not count, even with both switches on, but other calls can still reach them.
- Windows, the signed-in user, sends the Run account's own Windows sign-in, only to hosts listed in Hosts that may receive the sign-in. The account, the Windows version and the server must all support it.
- Windows, another user, signs in with Domain, Username and Password.
Redirects. Get and Get file stream follow redirects, up to 9; the tenth fails. With sign-in, a redirect to another site (scheme, host or port) fails. Without sign-in, your custom headers are not sent to the other site. Delete, Post, Put and Patch fail on a redirect. A redirect with no Location is handled like any error status.
Rows. Headers, Fields, Parts and Substitutions are rows that you type in the editor, not Dictionary variables. Headers and Fields have Enabled, Name and Value; Parts add Type (Text or File); Substitutions have Name and Value. Disabled and empty rows are skipped. A used row needs a name.
When a call fails. An error status (not 200 to 299) fails the step unless Keep a failure response is on. A time limit, a blocked address, a refused redirect or an unreadable upload file always fails. The Run log leaves out user information (name and password), query and fragment of the address; outputs and saved files still hold what the service sent.
Request and normal response bodies are held in memory. Post and Put stream multipart files from disk unless you buffer them; Get file stream writes straight to disk.
Shared fields
Content types
Each item gives the identifier, the editor label and what is sent.
None(None), Delete only: No body.application/json(JSON): Body text as UTF-8, for example{"name":"sample"}.application/xml(XML (application/xml)): Body text as UTF-8, for example<item>sample</item>.text/xml(XML (text/xml)): XML text with the text/xml type.text/plain(Text): Plain UTF-8 text, for examplesample.text/html(HTML): HTML text, for example<p>sample</p>.application/x-www-form-urlencoded(Form, URL encoded): Enabled Fields rows.name=two wordsbecomesname=two+words.multipart/form-data(Form, multipart), Post, Put, Patch: Enabled Parts rows; the boundary is made for you.Binary(A file): The File bytes, as application/octet-stream.custom(Another type): Body text with Media type, parameters kept; a charset sets the encoding.
Connection
Delete, Get, Get file stream, Patch, Post and Put all have these inputs.
In the When column, a dash (-) means the field is always shown.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
uri | URL | Stringdefault "" | Required. | Full HTTP or HTTPS address with its query, such as https://. |
proxy | Proxy | Proxydefault SYSTEM | - | SYSTEM (The system's): the Device proxy setting, used as set. NONE (None): direct. CUSTOM (Custom): Host and Port below. |
proxy | Host | Stringdefault "" | proxy = CUSTOM | Proxy host name, such as proxy.example.com, not the target address. |
proxy | Port | Numberdefault 0 | proxy = CUSTOM | Proxy port, such as 8080. The default 0 does not work. |
proxy | Username | Stringdefault "" | proxy = CUSTOM | Proxy account, such as sample-reader. Empty for no proxy sign-in. |
proxy | Password | Stringdefault "" | proxy = CUSTOM | Proxy password from a String variable, not a Credential. |
authentication | Authentication | Authdefault No | - | No (None), Basic, Bearer (Bearer token), Logged (Windows, the signed-in user) or Any (Windows, another user). See sign-in rules. |
basic | Username | Stringdefault "" | authentication = Basic | Service user name, such as sample-reader. Sent with the password in the Authorization header. |
basic | Password | Stringdefault "" | authentication = Basic | Service password from a String variable, not a Credential. |
bearer | Token | Stringdefault "" | authentication = Bearer | Only the token. The action adds Bearer . |
windows | Hosts that may receive the sign-in | Listdefault [] | authentication = Logged | List of exact host names, such as one String api.example.com. Case and a final dot are ignored. No wildcards, URLs or ports. Empty sends the sign-in to no host. |
auth | Domain | Stringdefault "" | authentication = Any | Domain of the other Windows account, such as EXAMPLE. |
ntlm | Username | Stringdefault "" | authentication = Any | Other Windows account name, such as sample-reader. |
ntlm | Password | Stringdefault "" | authentication = Any | Other Windows account password from a String variable. |
custom | Headers | Rowsdefault empty rows | - | Rows such as Accept = application/. A Content-Type header replaces the body type and does not change the bytes. |
time | Wait at most | Numberdefault 60000 | - | Milliseconds, such as 60000 for one minute. 0 or less means no time limit. After the headers arrive, a download copy still stops if the Run is cancelled. |
allow | Allow an insecure connection | Booleandefault false | - | false checks the server certificate. true accepts any certificate. Also needed for Basic or Bearer over HTTP; see sign-in rules. |
client | Client certificate | Stringdefault "" | - | A PKCS#12 file (.pfx) with its private key, such as samples/, if the service needs one; otherwise empty. The Run account must be able to use the key. |
client | Certificate password | Stringdefault "" | - | Certificate password from a String variable. Empty for a file without a password. |
allow | Allow an address inside the network | Booleandefault false | - | false blocks addresses on this PC or inside your network. true allows them for this step and its redirects. Certificate checks and the redirect rules for sign-in still apply. See address rules. |
Request body
Delete, Patch, Post and Put have these inputs. Text types are application/json, application/xml, text/xml, text/plain, text/html, custom.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
custom | Media type | Stringdefault "" | header = custom | Another type, such as application/ or text/. Sent as written. A charset sets the encoding; otherwise UTF-8. Empty sends text/plain. |
body | Body | Stringdefault "" | header = text type | The whole text body, such as {"name":"{{item}}"}. JSON and XML are not checked. Substitutions do not escape special characters. |
string | Substitutions | Rowsdefault empty rows | header = text type | Name/Value rows. item = sample replaces {{item}} in Body with sample, as plain text. Case counts; rows run in order; placeholders with no row stay. |
url | Fields | Rowsdefault empty rows | header = application/ | Rows such as q = two words. Names and values are encoded: q=. Do not encode them yourself. |
binary | File | Stringdefault "" | header = Binary | A readable file, such as samples/. Read fully into memory and sent as application/octet-stream. |
Response outputs
Delete, Get, Patch, Post and Put return these.
| Output | Meaning |
|---|---|
response | Dictionary of Strings. Bind to $reply$ to read $reply.Status$, $reply.Body$ and each header by its exact name. Status is text here; a header with several values is joined with commas. |
status | Number: the HTTP status, for example 200 or 404. Bind to a Number variable for decisions. |
body | String: the response as UTF-8 text. Bind to $body. For a binary download, use the saved file, not this text. |
Dictionary
Number
String
response is Dictionary, status is Number, and body is String.Response options
Delete, Get, Patch, Post and Put have these inputs. Get file stream does not.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
capture | Keep a failure response | Booleandefault false | - | false: an error status fails. true: returns its status, body and headers. DNS, connection, TLS, timeout and policy errors still fail; see when a call fails. |
accept | Accept cookies | Booleandefault false | - | true: send and keep cookies in this Run's cookie store, shared with later REST steps that also turn this on. false: no cookies for this call; the store is not cleared. The store ends with the Run. |
Actions
Build URL with parameters (restBuildUrl)
Add query parameters from a Dictionary to a base URL. No request is sent.
Inputs
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
base | Base URL | Stringdefault "" | Required. | The base address, such as https://. If it has a query, & is added; otherwise ?. The URL is not checked. |
query | Query parameters | Dictionarydefault {} | - | A Dictionary variable, such as $query$ with key q and String value two words. Names are always encoded. Other types use their stored text. |
encode | URL-encode parameter values | Booleandefault true | - | true encodes the values. false adds them as written, so special characters can change the query. |
Outputs
| Output | Type | Meaning |
|---|---|---|
result | String | The built URL. Bind to $url$ for a later URL input. |
Example
Create Dictionary $query$ with String q = two words. Set Base URL = https://api.example.com/search, Query parameters = $query$, URL-encode parameter values = true. Bind result to $url$.
Expected result
$url$ is https://api.example.com/search?q=two%20words. With encoding off, it has a plain space. An empty Dictionary returns the base unchanged. A # fragment in the base is not moved after the new parameters, so add fragments to the final URL yourself.
Decode URL (restDecodeUrl)
Decode % codes in one part of a URL. A + stays + (this is not form decoding).
Inputs
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
source | URL-encoded string | Stringdefault "" | Required. | Encoded text, such as two%20words%2. |
Outputs
| Output | Type | Meaning |
|---|---|---|
result | String | The decoded text. Bind to $decoded$. |
Example
Set URL-encoded string = two%20words%2Bmore. Bind result to String $decoded$.
Expected result
$decoded$ is two words+more. Empty text returns empty text.
Delete method (restDelete)
Send a DELETE request, normally without a body. Test only on an item you can lose.
Inputs
Also uses the response options.
Also uses the connection fields and the request body fields.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
header | Content type | Stringdefault None | - | See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart. |
Outputs
Returns the response outputs.
Example
Create a test item sample-42 on a test service that answers DELETE with 204. Set URL = https://api.example.com/items/sample-42, Proxy = NONE, Content type = None. Bind status to Number $status$ and body to String $bodyText$.
Expected result
On that service, the item is removed, status is 204 and body is empty. None sends no body, even if old text is still in Body. The other formats can send a body; multipart is not offered. What a status means depends on the service.
Encode URL (restEncodeUrl)
Encode one path part or value with % codes.
Inputs
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
source | String to encode | Stringdefault "" | Required. | One part, such as two words+more. Separators such as / and ? are encoded too, so do not give a full URL. |
Outputs
| Output | Type | Meaning |
|---|---|---|
result | String | The encoded text. Bind to $encoded$ to put into a URL. |
Example
Set String to encode = two words+more. Bind result to String $encoded$.
Expected result
$encoded$ is two%20words%2Bmore. A space becomes %20, not +. Empty text returns empty text.
Get method (restGet)
Send a GET request; you can also save the response to a file. Use Get file stream for large downloads.
Inputs
Also uses the response options.
Also uses the connection fields.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
download | Save the response to a file | Booleandefault false | - | true also writes the raw response bytes to File path. The three outputs stay, and the response is still held in memory. |
download | File path | Stringdefault "" | download = true | Where to save, such as samples/. Missing folders are created. |
overwrite | Overwrite a file that exists | Booleandefault false | download = true | false fails if the file exists. true replaces it. |
Outputs
Returns the response outputs.
Example
Use a test service that returns status 200 and body {"id":42}. Set URL = https://api.example.com/items/42, Proxy = NONE, Authentication = NoAuthentication. Add enabled Headers row Accept = application/json. Bind response to Dictionary $reply$, status to Number $status$, and body to String $bodyText$. To save it too, enable Save the response to a file and set File path = samples/item.json.
Expected result
For that response, status is Number 200, body is {"id":42} and $reply.Status$ is String 200. With saving on, the file has the raw response bytes. An existing file fails unless overwrite is on.
Get file stream (restGetFileStream)
Download a large file with GET straight to disk. No response Dictionary, cookies or Keep a failure response.
Inputs
Also uses the connection fields.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
file | File path | Stringdefault "" | Required. | Where to write the download, such as samples/. Missing folders are created. The Run account must be able to write there. |
overwrite | Overwrite a file that exists | Booleandefault false | - | false fails if the file exists. true replaces it while the response is copied. A cancelled or failed copy can leave a partial file. |
Outputs
| Output | Type | Meaning |
|---|---|---|
file | String | Full path of the written file. Use it in a String or File path input in the next step. |
Example
Use a test service that returns the bytes of a sample file with status 200. Set URL = https://api.example.com/files/sample.bin, Proxy = NONE, File path = samples/download.bin, Overwrite a file that exists = false. Bind file to String $downloadPath$.
Expected result
The file holds the response bytes and file is its full path. The response is not held in memory. An error status fails before the copy. An existing file fails with overwrite off.
Patch method (restPatch)
Send a PATCH request with a body.
Inputs
Also uses the response options.
Also uses the connection fields and the request body fields.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
header | Content type | Stringdefault application/ | - | See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart. |
form | Parts | Rowsdefault empty rows | header = multipart/ | Rows with Type Text (sends Value) or File (reads the file at Value), such as document, File, samples/. Use different part names if the server needs them. Not in Delete. |
Outputs
Returns the response outputs.
Example
Create samples/payload.bin with bytes representing the text sample-data. Set URL = https://api.example.com/items/sample-42, Proxy = NONE, Content type = Binary, File = samples/payload.bin. Use a test service that answers 200 and body patched. Bind status to Number $status$, body to String $bodyText$, and response to Dictionary $reply$.
Expected result
The service gets the file bytes as application/octet-stream. For that response, status is 200 and body is patched. Patch always reads multipart files into memory; there is no switch.
Post method (restPost)
Send a POST request with a body.
Inputs
Also uses the response options.
Also uses the connection fields and the request body fields.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
header | Content type | Stringdefault application/ | - | See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart. |
form | Parts | Rowsdefault empty rows | header = multipart/ | Rows with Type Text (sends Value) or File (reads the file at Value), such as document, File, samples/. Use different part names if the server needs them. Not in Delete. |
file | Buffer a file before upload | Booleandefault false | header = multipart/ | Post and Put only. false streams files from disk in chunks. true reads them into memory first so the request length is known; turn it on if the server refuses chunked uploads. Patch always reads multipart files into memory. |
Outputs
Returns the response outputs.
Example
Set URL = https://api.example.com/items, Proxy = NONE, Content type = application/json, Body = {"name":"{{item}}"}. Add Substitutions row item = sample. Use a test service that returns 201 and {"id":42} after it creates this test item. Bind status to Number $status$, body to String $bodyText$, and response to Dictionary $reply$.
Expected result
The service gets the body {"name":"sample"} as UTF-8 JSON. For that response, status is 201 and body is {"id":42}.
Put method (restPut)
Send a PUT request with a body.
Inputs
Also uses the response options.
Also uses the connection fields and the request body fields.
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
header | Content type | Stringdefault application/ | - | See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart. |
form | Parts | Rowsdefault empty rows | header = multipart/ | Rows with Type Text (sends Value) or File (reads the file at Value), such as document, File, samples/. Use different part names if the server needs them. Not in Delete. |
file | Buffer a file before upload | Booleandefault false | header = multipart/ | Post and Put only. false streams files from disk in chunks. true reads them into memory first so the request length is known; turn it on if the server refuses chunked uploads. Patch always reads multipart files into memory. |
Outputs
Returns the response outputs.
Example
Use a disposable test item. Set URL = https://api.example.com/items/sample-42, Proxy = NONE, Content type = application/x-www-form-urlencoded. Add enabled Fields rows name = sample and note = two words. The test service answers 200 and body updated. Bind status to Number $status$, body to String $bodyText$, and response to Dictionary $reply$.
Expected result
The service gets the body name=sample¬e=two+words. For that response, status is 200 and body is updated. The server can replace the item, so use a test item.
Get query parameters (restQueryParameters)
Read the query of an address into a Dictionary. No request is sent.
Inputs
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
url | URL string | Stringdefault "" | Required. | A URL or text with a query, such as https://. The text after the first ? and before # is read. |
decode | Decode parameter names | Booleandefault false | - | true decodes names; false keeps names such as item%20name as written. Case counts. |
decode | Decode parameter values | Booleandefault true | - | true decodes values; false keeps %20 and similar codes. A + stays +. |
Outputs
| Output | Type | Meaning |
|---|---|---|
result | Dictionary | Query names with String values. Bind to $query$. |
Example
Set URL string = https://api.example.com/search?q=two%20words&tag=a&tag=b#top, Decode parameter names = false, Decode parameter values = true. Bind result to Dictionary $query$.
Expected result
The Dictionary holds String q = two words and tag = b: a repeated name keeps its last value. A name without = has an empty value. No ? gives an empty Dictionary.
Get URL hostname (restUrlHostname)
Read the host name from a full URL. No name lookup or request is sent.
Inputs
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
source | URL string | Stringdefault "" | Required. | A full URL, for example https://. Spaces around it are removed. |
Outputs
| Output | Type | Meaning |
|---|---|---|
result | String | The host name, without the port. Bind to $host$. |
Example
Set URL string = https://api.example.com:8443/items?q=1. Bind result to a String variable.
Expected result
The result is api.example.com, without the port 8443. A relative or invalid URL fails.
Get URL protocol (restUrlProtocol)
Read the scheme from a full URL. No name lookup or request is sent.
Inputs
| Input | Editor field | Type; default | When / required | Use |
|---|---|---|---|---|
source | URL string | Stringdefault "" | Required. | A full URL, for example https://. Spaces around it are removed. |
Outputs
| Output | Type | Meaning |
|---|---|---|
result | String | The scheme without :, normally http or https. Bind to $scheme$. It also reads schemes that the request actions cannot use. |
Example
Set URL string = https://api.example.com:8443/items?q=1. Bind result to a String variable.
Expected result
The result is https, without :. A relative or invalid URL fails.