RESTDataSource Call() Method

Invokes a REST call using a specified HTTP verb.

Function Signature

 bool Call( verb, string& out, sPostData [, string accept, string contentType ] )

bool Call( verb, string& out, sPostData, Vector params 
           [, string accept, string contentType ] )

bool Call( verb, string& out, sPostData, Vector params, Vector pathParams 
           [, string accept, string contentType ] )

bool Call( verb, string& out, sPostData, Vector params, Vector pathParams, 
           Vector headers [, Vector& responseHeaders ] )

Parameters

Parameter Type Description

verb

string or value from HTTPVerbConstants

Specifies the HTTP verb. Use a string to specify a custom verb; otherwise, use HTTPVerbConstants. See HTTPVerbConstants.

out

string&

(Output) Filled with the resulting data from the REST call. If JSON, consider using from_json to parse this value.

sPostData

string

Data to send in the body of the call. Potentially, to send well-formatted JSON, set up the data to send in Maps and Vectors, and then call to_json to prepare a JSON value to pass into this parameter. Not sent if the verb is GET or HEAD.

accept

string

Optional. Sent as the HTTP Accept header value.

contentType

string

Optional. Sent as the HTTP Content-Type header value.

params

Vector

An optional Vector of Pair values of URL parameters (values that occur after the ? in the URL). Values will be bound to the URL parameters in a "first=second" format. Values that match URL parameters from the RESTDataSource URL will override the values from the URL, while values that do not match existing URL parameters will be appended to the URL.

To remove all params from the URL, send [ Nothing ]. To remove specific params, send [ Pair( "paramToRemove" , Nothing ) ]; send multiple Pairs to specify multiple values and/or remove multiple URL parameters.

pathParams

Vector

An optional Vector of string values of URL path parameters (values that occur after the server:port and before the ? in the URL). Values from the Vector will appear in order with / separators between them. The pathParams from the RESTDataSource URL will be processed in order while the pathParams Vector is processed in order; the values from the pathParams Vector will override the corresponding values from the RESTDataSource URL unless the Vector value is a blank string (indicates the value is kept from the RESTDataSource URL).

Use the Nothing object to delete pathParams from the URL. If there are more values in the Vector than the RESTDataSource URL, they will be appended to the URL.

headers

Vector

An optional Vector of Pair values that are sent as HTTP headers in a "name: value" format. Values will be header-encoded.

responseHeaders

Vector&

(Output) An optional Vector that is filled in with Pair(string,string) objects representing the HTTP headers that are received.

Return

Type Description

bool

Returns true if the call succeeds. On failure, Shell.GetLastErrorMessage() will provide more information.

Technical Details

SBM ModScript version: 11.4.

Example

var result = " ";
//Create AppRecord of RESTDATASOURCE table
var restSource = Ext.CreateAppRecord(Ext.TableId("TS_RESTDATASOURCE"));
restSource.ReadByColumn("TS_NAME", "JSONPlaceHolder1");
var sPostData = //Use Map with to_json to format JSON post data
       ["name": "myObjName", 
        "value1": 17, "value2": 5.7, 
		      "arrayData": [1,2,"3",4] //Use Vector for JSON array
	      ].to_json();
if (!restSource.Call(HTTPVerbConstants.PUT , result, sPostData)){
 // write an error to Event Viewer
	Ext.LogErrorMsg("Rest call failed in script " + __FILE__ + 
   ":\n" + Shell.GetLastErrorMessage() );
	
 // write an error to Active Diagnostics
	ADLog.Message( __FILE__, __LINE__, ADLogLevelConstants.ERROR, 
   "Rest call failed:\n" + Shell.GetLastErrorMessage() );
	
	Shell.RedoMessage() = "Rest call failed";
	
	ExitScript(); 
} 

Notes

Use with HTTPVerbConstants.PUT to invoke a REST PUT call. Default timeout is 30 seconds. To override the default timeout value, you must add a new entry to the TS_SYSTEMSETTINGS table called DefaultRESTTimeout with TS_DATATYPE set to 1 and specify the desired timeout in the TS_LONGVALUE column.

The SBMProxy only allows certain HTTP verbs; therefore, use UseSBMProxy( false ) if necessary.

Override the default timeout by changing the value of Shell.RESTTimeout()β€”the expected value is an integer number of seconds.

Tip: To view a script that provides sample code for using params and pathParams, refer to the RESTDataSource.tscm script in the installDir\SBM\Application Engine\ModScript_Examples directory on the Application Engine server or see Sample Five: RESTDataSource.

Related Topics

RESTDataSource