PALATINELABSDocsENES

Pages

↑↓ to moveEnter to openEsc to close

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.

Jump to actions

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.

Sign-in rules.

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.

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.

InputEditor fieldType; defaultWhen / requiredUse
uriURLStringdefault ""Required.Full HTTP or HTTPS address with its query, such as https://api.example.com/items/42⁠.
proxyTypeProxyProxyModedefault SYSTEM-SYSTEM (The system's): the Device proxy setting, used as set. NONE (None): direct. CUSTOM (Custom): Host and Port below.
proxyHostHostStringdefault ""proxyType = CUSTOMProxy host name, such as proxy.example.com⁠, not the target address.
proxyPortPortNumberdefault 0proxyType = CUSTOMProxy port, such as 8080⁠. The default 0 does not work.
proxyUserUsernameStringdefault ""proxyType = CUSTOMProxy account, such as sample-reader⁠. Empty for no proxy sign-in.
proxyPasswordPasswordStringdefault ""proxyType = CUSTOMProxy password from a String variable, not a Credential.
authenticationModeAuthenticationAuthModedefault NoAuthentication-NoAuthentication (None), Basic⁠, Bearer (Bearer token), LoggedInAdUser (Windows, the signed-in user) or AnyAdUser (Windows, another user). See sign-in rules.
basicUserNameUsernameStringdefault ""authenticationMode = BasicService user name, such as sample-reader⁠. Sent with the password in the Authorization header.
basicPasswordPasswordStringdefault ""authenticationMode = BasicService password from a String variable, not a Credential.
bearerTokenTokenStringdefault ""authenticationMode = BearerOnly the token. The action adds Bearer ⁠.
windowsAuthAllowedHostsHosts that may receive the sign-inListdefault []authenticationMode = LoggedInAdUserList 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.
authDomainDomainStringdefault ""authenticationMode = AnyAdUserDomain of the other Windows account, such as EXAMPLE⁠.
ntlmUserNameUsernameStringdefault ""authenticationMode = AnyAdUserOther Windows account name, such as sample-reader⁠.
ntlmPasswordPasswordStringdefault ""authenticationMode = AnyAdUserOther Windows account password from a String variable.
customHeadersHeadersRowsdefault empty rows-Rows such as Accept = application/json⁠. A Content-Type header replaces the body type and does not change the bytes.
timeOutWait at mostNumberdefault 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.
allowInsecureConnectionAllow an insecure connectionBooleandefault false-false checks the server certificate. true accepts any certificate. Also needed for Basic or Bearer over HTTP; see sign-in rules.
clientCertificatePathClient certificateStringdefault ""-A PKCS#12 file (.pfx) with its private key, such as samples/client.pfx⁠, if the service needs one; otherwise empty. The Run account must be able to use the key.
clientCertificatePasswordCertificate passwordStringdefault ""-Certificate password from a String variable. Empty for a file without a password.
allowInternalNetworkAllow an address inside the networkBooleandefault 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.

InputEditor fieldType; defaultWhen / requiredUse
customContentTypeMedia typeStringdefault ""headerContentType = customAnother type, such as application/vnd.example+json or text/plain; charset=iso-8859-1⁠. Sent as written. A charset sets the encoding; otherwise UTF-8. Empty sends text/plain.
bodyBodyStringdefault ""headerContentType = text typeThe whole text body, such as {"name":"{{item}}"}⁠. JSON and XML are not checked. Substitutions do not escape special characters.
stringSubstitutionSubstitutionsRowsdefault empty rowsheaderContentType = text typeName/Value rows. item = sample replaces {{item}} in Body with sample⁠, as plain text. Case counts; rows run in order; placeholders with no row stay.
urlEncodedPostParametersFieldsRowsdefault empty rowsheaderContentType = application/x-www-form-urlencodedRows such as q = two words⁠. Names and values are encoded: q=two+words⁠. Do not encode them yourself.
binaryFileFileStringdefault ""headerContentType = BinaryA readable file, such as samples/payload.bin⁠. Read fully into memory and sent as application/octet-stream.

Response outputs

Delete, Get, Patch, Post and Put return these.

OutputMeaning
responseDictionary 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.
statusNumber: the HTTP status, for example 200 or 404⁠. Bind to a Number variable for decisions.
bodyString: the response as UTF-8 text. Bind to $bodyText$⁠. For a binary download, use the saved file, not this text.
The HTTP response supplies three output types: 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.

InputEditor fieldType; defaultWhen / requiredUse
captureFailureResponseKeep a failure responseBooleandefault 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.
acceptCookiesAccept cookiesBooleandefault 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

InputEditor fieldType; defaultWhen / requiredUse
baseUrlBase URLStringdefault ""Required.The base address, such as https://api.example.com/search⁠. If it has a query, & is added; otherwise ?⁠. The URL is not checked.
queryParamsQuery parametersDictionarydefault {}-A Dictionary variable, such as $query$ with key q and String value two words⁠. Names are always encoded. Other types use their stored text.
encodeValuesURL-encode parameter valuesBooleandefault true-true encodes the values. false adds them as written, so special characters can change the query.

Outputs

OutputTypeMeaning
resultStringThe 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.

Back to actions

Decode URL (restDecodeUrl)

Decode % codes in one part of a URL. A + stays + (this is not form decoding).

Inputs

InputEditor fieldType; defaultWhen / requiredUse
sourceStringURL-encoded stringStringdefault ""Required.Encoded text, such as two%20words%2Bmore⁠.

Outputs

OutputTypeMeaning
resultStringThe 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.

Back to actions

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.

InputEditor fieldType; defaultWhen / requiredUse
headerContentTypeContent typeStringdefault 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.

Back to actions

Encode URL (restEncodeUrl)

Encode one path part or value with % codes.

Inputs

InputEditor fieldType; defaultWhen / requiredUse
sourceStringString to encodeStringdefault ""Required.One part, such as two words+more⁠. Separators such as / and ? are encoded too, so do not give a full URL.

Outputs

OutputTypeMeaning
resultStringThe 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.

Back to actions

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.

InputEditor fieldType; defaultWhen / requiredUse
downloadFileSave the response to a fileBooleandefault false-true also writes the raw response bytes to File path. The three outputs stay, and the response is still held in memory.
downloadFileNameFile pathStringdefault ""downloadFile = trueWhere to save, such as samples/download.bin⁠. Missing folders are created.
overwriteDownloadFileOverwrite a file that existsBooleandefault falsedownloadFile = truefalse 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.

Back to actions

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.

InputEditor fieldType; defaultWhen / requiredUse
filePathFile pathStringdefault ""Required.Where to write the download, such as samples/download.bin⁠. Missing folders are created. The Run account must be able to write there.
overwriteOverwrite a file that existsBooleandefault 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

OutputTypeMeaning
fileStringFull 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.

Back to actions

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.

InputEditor fieldType; defaultWhen / requiredUse
headerContentTypeContent typeStringdefault application/json-See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart.
formDataPartsRowsdefault empty rowsheaderContentType = multipart/form-dataRows with Type Text (sends Value) or File (reads the file at Value), such as document⁠, File⁠, samples/invoice.txt⁠. 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.

Back to actions

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.

InputEditor fieldType; defaultWhen / requiredUse
headerContentTypeContent typeStringdefault application/json-See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart.
formDataPartsRowsdefault empty rowsheaderContentType = multipart/form-dataRows with Type Text (sends Value) or File (reads the file at Value), such as document⁠, File⁠, samples/invoice.txt⁠. Use different part names if the server needs them. Not in Delete.
fileBufferingEnabledBuffer a file before uploadBooleandefault falseheaderContentType = multipart/form-dataPost 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}.

Back to actions

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.

InputEditor fieldType; defaultWhen / requiredUse
headerContentTypeContent typeStringdefault application/json-See content types. Text types send Body, forms send rows, Binary sends File. Delete also offers None and has no multipart.
formDataPartsRowsdefault empty rowsheaderContentType = multipart/form-dataRows with Type Text (sends Value) or File (reads the file at Value), such as document⁠, File⁠, samples/invoice.txt⁠. Use different part names if the server needs them. Not in Delete.
fileBufferingEnabledBuffer a file before uploadBooleandefault falseheaderContentType = multipart/form-dataPost 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&note=two+words. For that response, status is 200 and body is updated. The server can replace the item, so use a test item.

Back to actions

Get query parameters (restQueryParameters)

Read the query of an address into a Dictionary. No request is sent.

Inputs

InputEditor fieldType; defaultWhen / requiredUse
urlStringURL stringStringdefault ""Required.A URL or text with a query, such as https://api.example.com/search?q=two%20words&tag=a&tag=b#top⁠. The text after the first ? and before # is read.
decodeNameDecode parameter namesBooleandefault false-true decodes names; false keeps names such as item%20name as written. Case counts.
decodeValuesDecode parameter valuesBooleandefault true-true decodes values; false keeps %20 and similar codes. A + stays +⁠.

Outputs

OutputTypeMeaning
resultDictionaryQuery 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.

Back to actions

Get URL hostname (restUrlHostname)

Read the host name from a full URL. No name lookup or request is sent.

Inputs

InputEditor fieldType; defaultWhen / requiredUse
sourceStringURL stringStringdefault ""Required.A full URL, for example https://api.example.com:8443/items⁠. Spaces around it are removed.

Outputs

OutputTypeMeaning
resultStringThe 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.

Back to actions

Get URL protocol (restUrlProtocol)

Read the scheme from a full URL. No name lookup or request is sent.

Inputs

InputEditor fieldType; defaultWhen / requiredUse
sourceStringURL stringStringdefault ""Required.A full URL, for example https://api.example.com/items⁠. Spaces around it are removed.

Outputs

OutputTypeMeaning
resultStringThe 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.

Back to actions