Asynchronous RESTMessageV2 example

You can send an outbound REST message asynchronously.

You can send a REST message asynchronously. When you send an asynchronous message the instance does not wait for a response before proceeding. You must handle waiting for a response within your code.

var requestBody;
var responseBody;
var status;
var sm;
	sm = new sn_ws.RESTMessageV2("Yahoo Finance", "get");  // Might throw exception if message doesn't exist or not visible due to scope.
	sm.setStringParameter("symbol", "NOW");
	response = sm.executeAsync(); //Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.

	response.waitForResponse(60);// In seconds. Wait at most 60 seconds to get response from ECC Queue/Mid Server //Might throw exception timing out waiting for response in ECC queue.

	responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
	status = response.getStatusCode();
} catch(ex) {
	responseBody = ex.getMessage();
	status = '500';
} finally {
	requestBody = sm ? sm.getRequestBody():null;
gs.log("Request Body: " + requestBody);
gs.log("Response: " + responseBody);
gs.log("HTTP Status: " + status);