Recorder API

sendingRequest eventType

request: Reference to the current request object.

Property Description
Method Method of the request. For example, GET, POST .
url Full URL string for the request.
headerNames Returns an array of the header names that exist in the request.
content Request content as a string.
contentBytes Request content as a byte array.

All the request properties are read-only. Individual headers can be accessed and modified using the methods listed below.

Method Description
getHeader(name) Returns the value of the header. If the header does not exist, it returns null . If there are multiple headers with the same name, it returns a string with a list separated by a comma followed by a space: for example, a, b, c .
addHeader(name, value) Adds the header to the request.
replaceHeader(name, value) If a header with the same name exists, the value is replaced with the new value. If the header does not exist, a new header is added.
removeHeader(name) Remove the header from the request.

Example code for sendingRequest

/** his code will intercept the first request where the URL contains
the substring 'submit.asp' and the request method is POST and it will
then add a cookie header to the request**/

if (request.url.indexOf('submit.asp') != -1 && request.method == 'POST'){
   	request.addHeader('cookie', 'myId=1234567');
}

replyReceived eventType

response: Reference the current reply object.

Property Description
request Request that resulted in this response. Any properties/methods defined for request can be accessed for this object.
status Status code from the result (for example 200 or 404 ).
headerNames Returns an array of the header names that exist in the reply.
content Reply content as a string.
contentBytes Reply content as a byte array.

All response properties are read-only.

Method Description
getHeader(name) Returns the value of the header. If the header does not exist, it returns null . If there are multiple headers with the same name, it returns a string with a list separated by a comma followed by a space: for example, a, b, c .

Example code for replyReceived

/** This code will intercept the first response where the URL contains the substring
'submit.asp' and the response return code is 200, and then will capture the orderId
value found in the response content**/

if (response.request.url.indexOf('submit.asp') != -1 && response.status == '200')
{
   	body = response.content;
    orderId = body.match(/orderId\=([0-9]+)/)[1];
}

SMS reply handler

result: Reference the current SMS reply.

Property Description
responseCode Response code from the SMS reply: 200 for success; error codes are in the 9000099999 range.
phoneNumber Phone number sending the SMS reply. This value is returned as a string, because the number may contain letters.
message SMS message received.

Example code for SMS reply handler

 if (result.responseCode == 200)
{
	smsMessage = result.message;
validationCode = smsMessage.match(/Code:\s+([0-9A-Z]+)\s+)[1];
}