RESTDataSource Get() Method

Invokes a REST call using GET.

Function Signature

 bool Get( string& out [ , string accept, string contentType ] )

bool Get( string& out, Vector params 
         [ , string accept, string contentType ] )

bool Get( string& out, Vector params, Vector pathParams 
         [ , string accept, string contentType ] )

bool Get( string& out, Vector params, Vector pathParams, Vector headers 
         [ , Vector& responseHeaders ] )

Parameters

Parameter Type Description

out

string&

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

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. See Pair, Map_Pair, and Dictionary_Pair.

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. See Pair, Map_Pair, and Dictionary_Pair.

responseHeaders

Vector&

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

Return

Type Description

bool

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

Technical Details

SBM ModScript version: 11.3. Extended in 11.4.

Example

var result = " ";
//Create AppRecord of RESTDATASOURCE table
var restSource = Ext.CreateAppRecord(Ext.TableId("TS_RESTDATASOURCE"));
restSource.ReadByColumn("TS_NAME", "JSONPlaceHolder1");
if (!restSource.Get(result)){
 // 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

The 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.

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