Working with REST APIs
abstract
Sahi exposes RESTRequest and RESTResponse APIs to work with REST APIs
info
Refer to this article for complete examples of how to use the REST APIs.
RESTRequest
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest()
Arguments
None |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest
Details
RESTRequest object is used to REST requests
RESTRequest object is used to REST requests
RESTRequest.addToQueryString
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.addToQueryString($key, $value)
Arguments
$key | string | query parameter key |
$value | string | query parameter value |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.add To Query String
Details
Adds a query parameter to the request URL
Adds a query parameter to the request URL
$request = new RESTRequest();
$request.addToQueryString("Place", "Bangalore");
Single argument can also be passed to this api. This can be a string which is queryString or Parameter object. Parameter object is explained below.- As query string
$request = new RESTRequest(); $request.addToQueryString("Place=Bangalore");
- As Parameter object
$request = new RESTRequest(); var $p = new Parameter(); $p.add("Name", "Jane"); $p.add("Age", "25"); $request.addToQueryString($p);
RESTRequest.addToBody
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.addToBody($key, $value)
Arguments
$key | string | query parameter key |
$value | string | query parameter value |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.add To Body
Details
Adds a query parameter to the request Body
Adds a query parameter to the request Body
$request = new RESTRequest();
$request.addToBody("Place", "Bangalore");
Single argument can also be passed to this api. This can be a string which is queryString or Parameter object. Parameter object is explained below.- As query string
$request = new RESTRequest(); $request.addToBody("Place=Bangalore");
- As Parameter object
$request = new RESTRequest(); var $p = new Parameter(); $p.add("Name", "Jane"); $p.add("Age", "25"); $request.addToBody($p);
RESTRequest.setHeader
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.setHeader($key, $value)
Arguments
$key | string | Header name |
$value | string | Header value |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.set Header
Details
Sets request header
Sets request header
$request = new RESTRequest();
$request.setHeader("Accept-Encoding", "deflate,sdch");
RESTRequest.setURL
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.setURL($url)
Arguments
$url | string | url to be navigated |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.set URL
Details
Sets url to be navigated
Sets url to be navigated
$request = new RESTRequest();
$request.setURL("http://sahi.co.in");
RESTRequest.setBody
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.setBody($body)
Arguments
$body | string | the body of the request. |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.set Body
Details
Sets body of the request. Pass a JSON string.
Sets body of the request. Pass a JSON string.
var $json = {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "Mumbai"
}
};
var $jsonString = JSON.stringify($json);
$request = new RESTRequest();
$request.setBody($jsonString);
info
SOAP requests can be made by setting the Soap request xml in the body of the request through setBody.
RESTRequest.setCredentials
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
6.0.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.setCredentials($username, $password[, $isEncrypted])
Arguments
$username | string | Username for authentication |
$password | string | Password for authentication |
$isEncrypted | boolean optional | Set as true if the password is encrypted |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.set Credentials
Details
Sets authentication parameters when trying to access an authorized page. Uses the credentials provided for 401 Authentication.
Sets authentication parameters when trying to access an authorized page. Uses the credentials provided for 401 Authentication.
$request = new RESTRequest();
$request.setCredentials("testuser", "password");
// Use encrypted password
$request = new RESTRequest();
$request.setCredentials("testuser", "MgkKEQBU", true);
info
- For encrypting the password use _encrypt or use password encoder from editor.
- Salt is used to encrypt the password. You can change the salt by changing the property
script.salt_for_password_encryption
inuserdata/config/userdata.properties
file. - If
script.salt_for_password_encryption
property is present inuserdata/config/userdata_hidden.properties
as well, then this property will be considered only fromuserdata_hidden.properties
file.
RESTRequest.setAuthCredentials
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
7.0.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.setAuthCredentials($oauthtype, $oauthvalue[, $isEncrypted])
Arguments
$oauthtype | string | oauthtype for authentication |
$oauthvalue | string | oauthvalue for authentication |
$isEncrypted | boolean optional | Set as true if the oauthvalue is encrypted |
Returns
null |
Sahi Pro Flowcharts Action :RESTRequest.set Auth Credentials
Details
Sets authentication parameters when trying to access an authorized page. Uses the credentials provided for Basic/oAuth1.0 Authentication.
Sets authentication parameters when trying to access an authorized page. Uses the credentials provided for Basic/oAuth1.0 Authentication.
// For Basic auth
$request = new RESTRequest();
$request.setAuthCredentials("authType", "Basic Auth");
$request.setAuthCredentials("userName", "testuser");
$request.setAuthCredentials("passWord", "password");
// For Basic auth with encrypted password
$request = new RESTRequest();
$request.setAuthCredentials("authType", "Basic Auth");
$request.setAuthCredentials("userName", "testuser");
$request.setAuthCredentials("passWord", "MgkKEQBU", true);
// For oAuth1.0
$request = new RESTRequest();
$request.setAuthCredentials("authType", "OAuth 1.0");
$request.setAuthCredentials("oauth_consumer_key", "consumer key");
$request.setAuthCredentials("oauth_consumer_secret", "consumer secret");
$request.setAuthCredentials("oauth_token", "token");
$request.setAuthCredentials("oauth_token_secret", "token secret");
$request.setAuthCredentials("oauth_signature_method", "HMAC-SHA1");
$request.setAuthCredentials("oauth_version", "1.0");
info
- For encrypting the password use _encrypt or use password encoder from editor.
- Salt is used to encrypt the password. You can change the salt by changing the property
script.salt_for_password_encryption
inuserdata/config/userdata.properties
file. - If
script.salt_for_password_encryption
property is present inuserdata/config/userdata_hidden.properties
as well, then this property will be considered only fromuserdata_hidden.properties
file.
RESTRequest.submit
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTRequest.submit($method[, $followRedirects])
Arguments
$method | string | request method, values can be "get", "post" or "delete" |
$followRedirects | boolean optional | Set this argument to false if the request should not automatically follow redirects. The default value is true. This argument is available since Sahi Pro v10.0.0. |
Returns
object | RESTResponse object |
Sahi Pro Flowcharts Action :RESTRequest.submit
Details
Submits the request, reads response and returns a RESTResponse object
Submits the request, reads response and returns a RESTResponse object
$request = new RESTRequest();
$request.setURL("http://sahi.co.in");
$response = $request.submit("get");
If this api is called before setURL it will return a null object
RESTResponse
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTResponse()
Arguments
None |
Returns
null |
Sahi Pro Flowcharts Action :RESTResponse
Details
RESTResponse object is used to read REST responses
RESTResponse object is used to read REST responses
RESTResponse.getResponseCode
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTResponse.getResponseCode()
Arguments
None |
Returns
string | Response code |
Sahi Pro Flowcharts Action :RESTResponse.get Response Code
Details
var $s = $response.getResponseCode(); //returns response code e.g. 200, 404 etc.
RESTResponse.getHeader
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTResponse.getHeader($key)
Arguments
$key | string | Header name |
Returns
string | Value of the specified response header |
Sahi Pro Flowcharts Action :RESTResponse.get Header
Details
var $s = $response.getHeader("Content-Length"); //returns value of content-length header
RESTResponse.getBodyAsString
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTResponse.getBodyAsString([$charSet])
Arguments
$charSet | string optional | Character set. Default is "UTF-8". |
Returns
string | Content of response body |
Sahi Pro Flowcharts Action :RESTResponse.get Body As String
Details
infoNOTE: $charSet was added Since Sahi Pro: 6.2.1. For old document Refer here
var $s = $response.getBodyAsString(); //returns the content of the body using UTF-8 encoding
var $s = $response.getBodyAsString("ISO-8859-1"); //returns the content of the body using ISO-8859-1 encoding
RESTResponse.getBody
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
RESTResponse.getBody()
Arguments
None |
Returns
array | Content of response body as byte array |
Sahi Pro Flowcharts Action :RESTResponse.get Body
Details
var $s = $response.getBody(); //returns the content of the body
Parameter
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
Parameter()
Arguments
None |
Returns
null |
Sahi Pro Flowcharts Action :Parameter
Details
Parameter object is used to add parameters to query string and body
Parameter object is used to add parameters to query string and body
Parameter.add
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
Parameter.add($key, $value)
Arguments
$key | string | parameter key |
$value | string | parameter value |
Returns
null |
Sahi Pro Flowcharts Action :Parameter.add
Details
Adds a key-value pair to Parameter object
Adds a key-value pair to Parameter object
var $p = new Parameter();
$p.add("Name", "Jane");
info
Note: Calling this method again with the same parameter name will add one more key-pair with the value specified.
var $p = new Parameter();
$p.add("Name", "Jane");
$p.add("Name", "Doe");
$p.getQueryString(); // returns Name=Jane&Name=Doe
Parameter.replace
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
8.0.0 | NA | NA | NA | NA |
Available for modes: Browser
Parameter.replace($key, $value[, $index])
Arguments
$key | string | parameter key |
$value | string | parameter value |
$index | integer optional | parameter Index |
Returns
null |
Sahi Pro Flowcharts Action :Parameter.replace
Details
Replace a key-value pair at a specified index in the Parameter object. If the index is not specified the all the values added previously will be replaced by the value specified.
Replace a key-value pair at a specified index in the Parameter object. If the index is not specified the all the values added previously will be replaced by the value specified.
var $p = new Parameter();
$p.add("Name", "Jane");
$p.add("Name", "Woo");
$p.replace("Name", "Doe", 1);
$p.getQueryString(); // returns Name=Jane&Name=Doe
Parameter.remove
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
Parameter.remove($key)
Arguments
$key | string | parameter key |
Returns
null |
Sahi Pro Flowcharts Action :Parameter.remove
Details
Removes a key-value pair(if exists) from Parameter object, specified by the key
Removes a key-value pair(if exists) from Parameter object, specified by the key
var $p = new Parameter();
$p.add("Name", "Jane");
$p.add("Age", "25");
$p.remove("Name");
Parameter.getQueryString
Since: | Sahi Pro | Desktop Add-On | Mobile Add-On | SAP Add-On | AI Assist Add-On |
5.1.0 | NA | NA | NA | NA |
Available for modes: Browser
Parameter.getQueryString()
Arguments
None |
Returns
string | query string |
Sahi Pro Flowcharts Action :Parameter.get Query String
Details
Creates a query string using all the key-value pairs in the Parameter object
Creates a query string using all the key-value pairs in the Parameter object
var $p = new Parameter();
$p.add("Name", "Jane");
$p.add("Age", "25");
var $qs = $p.getQueryString();