Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This server class allows operating with the REST API methods and parameters.

Tip

Change the REST_message_record text from the examples below to the record name of your REST message.

SimpleRestRequestApi()


Initialises an empty SimpleRestRequestApi object. When using such object, specify the method and the endpoint manually.

SimpleRestRequestApi(requestName, methodName)


Creates an instance of the SimpleRestRequestApi object using information from the REST message record. You need to have a REST record before using this constructor.


NameTypeMandatoryDefault Value
requestNameStringYN
methodNameStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titleSimpleRestRequestApi
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get')

execute()


Sends the REST message.


Return:

TypeDescription
SimpleRestResponseResponse to the message sent by the execute() method.


Example:

Code Block
languagejs
themeEclipse
titleexecute
varconst sm = sws.restRequestV1('slack_platform', 'send_message');
      sm.setRequestBody(json_m);
      sm.execute();


setBasicAuth(userName, userPass)


Sets the username for web-service auth if the basic auth type was chosen. 


Parameter(s):

NameTypeMandatoryDefault Value
userNameStringYN
userPassStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetBasicAuth
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
sm.setBasicAuth('username', 'password');


setRequestUrl(requestUrl)


Sets the request URL.


Parameter(s):

NameTypeMandatoryDefault Value
requestUrlStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetRequestUrl
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
sm.setRequestUrl(“url”);


setRequestMethod(methodName)


Sets the requesting method (GET, POST, PURGE, etc). Accepts the requesting method name.


Parameter(s):

NameTypeMandatoryDefault Value
methodNameStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetRequestMethod
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
sm.setRequestMethod('get');


setRequestTimeout(timeout)


Sets the response timeout until the request is out of time.


Parameter(s):

NameTypeMandatoryDefault Value
timeoutIntegerYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetRequestTimeout
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
sm.setRequestTimeout('60000');


setQueryParameter(name, value)


Adds a parameter into the end of the request URL generated as "name=value",


Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN
valueStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetQueryParameter
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
sm.setQueryParameter('sysparm_query', 'active=true^ORDERBYDESCcategory');


setRequestBody(body)


Sets the request body when used PUT or POST methods.


Parameter(s):

NameTypeMandatoryDefault Value
bodyStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetRequestBody
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
varconst body = '<Message body content>';
sm.setRequestBody(body);


setStringParameter(name, value)


Sets the request variable with the name specified from the record to the value specified.


Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN
valueStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetStringParameter
varconst sm = new sws.RestRequest('<REST_request_record>','get'); 
sm.setStringParameter('s','NOW');


setRequestHeader(name, value)


Sets the HTTP header in the request for the value specified.


Parameter(s):

NameTypeMandatoryDefault Value
nameStringYN
valueStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlesetRequestHeader
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
sm.setRequestHeader('Accept', 'Application/json');


getRequestUrl()


Displays the request URL with parameters.


Return:

TypeDescription
StringThe request URl.


Example:

Code Block
languagejs
themeEclipse
titlegetRequestUrl
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
varconst url = sm.getRequestUrl();


getRequestBody()


Returns the request body.


Return:

TypeDescription
StringThe request body.


Example:

Code Block
languagejs
themeEclipse
titlegetRequestBody
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
varconst body = sm.getRequestBody();


getRequestHeaders()


Returns all the requested headers.


Return:

TypeDescription
ArrayThe requested headers.


Example:

Code Block
languagejs
themeEclipse
titlegetRequestHeaders
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
varconst headers = sm.getRequestHeaders();


getRequestMethod()


Returns the requesting method


Return:

TypeDescription
StringThe method name.


Example:

Code Block
languagejs
themeEclipse
titlegetRequestMethod
varconst sm = new sn_wssws.SimpleRestRequestV1restRequestV1('REST_message_record', 'get');
varconst method = sm.getRequestMethod();


Table of Contents
absoluteUrltrue
classfixedPosition