Skip to main content

SrwAsyncApi

Sabre Red 360 Developer Toolkit provides a capability to execute several services from a Red App web module.

Acquiring SrwAsyncApi

In order to obtain SrwAsyncApi and use you need to import it, e.g.

import {SrwAsyncApi} from "sabre-ngv-app/app/services/impl/SrwAsyncApi";

Then inside your source obtain the service as follows:

const srwApi = getService(SrwAsyncApi);

Available methods

There are several methods available in SrwAsyncApi, all of which are asynchronous, below you can find detailed list of them.

sws
sws(xml: string, action: string, callback: Object): void;

Type Parameteres:
xml - string containing xml request
action - action code for request
callback - function that should be called with result

swsWithLock
swsWithLock(xml: string, action: string, lockId: number, callback: Object): void;

Type Parameteres:
xml - string containing xml request
action - action code for request
lockId - lock id to be used while sending request to SWS
callback - function that should be called with result

lock
lock(callback: Object): void;

Type Parameteres:
callback - function that should be called with result

lockWithTimeout
lockWithTimeout(timeout: number, callback: Object): void;

Type Parameteres:
timeout - specifies acquired lock timeout, after which it will be invalidated
callback - function that should be called with result

tryLock
tryLock(duration: number, lockWaitingTimeout: number, callback: Object): void;

Type Parameteres:
duration - specifies for how long acquired lock will remain valid
lockWaitingTimeout - specifies for how long the caller is willing to wait for lock as it may not be available immediately
callback - function that should be called with result

unlock
unlock(lockId: number, callback: Object): void;

Type Parameteres:
lockId - lock to be unlocked
callback - function that should be called with result

showInEmu
showInEmu(text: string, isCommand: boolean, functionObject: Object): void;

Type Parameteres:
text - text or command to be shown in emulator
isCommand - specifies if provided text should be shown as command (plain text otherwise)
callback - function that should be called with result

executeInEmu
executeInEmu(command: string, showCommand: boolean, showResponse: boolean, functionObject: Object): void;

Type Parameteres:
command - command to be executed in emulator
showCommand - specifies if provided command should be shown in emulator
showResponse - specifies if command response should be shown in emulator
callback - function that should be called with result

rest2Sg
rest2Sg(url: string, httpMethod: HttpMethod, authTokenType: AuthTokenType, payload: string, contentType: string, functionObject: Object): void;

Type Parameters:
url - path to Sabre REST service ex. "/v1/lists/utilities/aircraft/equipment"
httpMethod - 'GET' 'POST' 'PUT' 'DELETE' 'HEAD' 'CONNECT' 'OPTIONS' 'TRACE' 'PATCH'
authTokenType - 'SESSION' or 'SESSIONLESS'
payload - JSON formatted string
contentType - content, application/json in most cases
functionObject - function that should be called with result

rest2SgWithLock
rest2SgWithLock(url: string, httpMethod: HttpMethod, authTokenType: AuthTokenType, payload: string, contentType: string, lockId: number, functionObject: Object): void;

Type Parameters:
url - path to Sabre REST service ex. "/v1/lists/utilities/aircraft/equipment"
httpMethod - 'GET' 'POST' 'PUT' 'DELETE' 'HEAD' 'CONNECT' 'OPTIONS' 'TRACE' 'PATCH'
authTokenType - 'SESSION' or 'SESSIONLESS'
payload - JSON formatted string
contentType - content, application/json in most cases
lockId - lock to be used when sending request
functionObject - function that should be called with result

rest2SgWithHeaders
rest2SgWithHeaders(url: string, httpMethod: HttpMethod, authTokenType: AuthTokenType, payload: string, contentType: string, headers: string, functionObject: Object): void;

Type Parameters:
url - path to Sabre REST service ex. "/v1/lists/utilities/aircraft/equipment"
httpMethod - 'GET' 'POST' 'PUT' 'DELETE' 'HEAD' 'CONNECT' 'OPTIONS' 'TRACE' 'PATCH'
authTokenType - 'SESSION' or 'SESSIONLESS'
payload - JSON formatted string
contentType - content, application/json in most cases
headers - JSON formatted string
functionObject - function that should be called with result

rest2SgWithHeadersAndLock
rest2SgWithHeadersAndLock(url: string, httpMethod: HttpMethod, authTokenType: AuthTokenType, payload: string, contentType: string, headers: string, lockId: number, functionObject: Object): void;

Type Parameters:
url - path to Sabre REST service ex. "/v1/lists/utilities/aircraft/equipment"
httpMethod - 'GET' 'POST' 'PUT' 'DELETE' 'HEAD' 'CONNECT' 'OPTIONS' 'TRACE' 'PATCH'
authTokenType - 'SESSION' or 'SESSIONLESS'
payload - JSON formatted string
contentType - content, application/json in most cases
headers - JSON formatted string
lockId - lock to be used
functionObject - function that should be called with result

Authorization

In order to be able to use specific services through SrwApi, your Red App needs to have authorization for those services in it’s redapp.xml file.

SWS:

<Authorization name="com.sabre.edge.cf.sws.SWS" threshold="[threshold]" metric="[metric]"/>

Locking/Unlocking:

<Authorization name="com.sabre.edge.cf.host.Locking" threshold="[threshold]" metric="[metric]" />

ShowInEmu:

<Authorization name="com.sabre.edge.cf.emu.ShowInEmulator" threshold="[threshold]" metric="[metric]" />

ExecuteInEmu:

<Authorization name="com.sabre.edge.cf.emu.ExecuteInEmulator" threshold="[threshold]" metric="[metric]" />

Rest2SG:

To be able to connect to a Rest endpoint, e.g.

/v4/lists/utilities/geocode/locations

and

/v1/lists/utilities/aircraft/equipment

You need to add authorization to redapp.xml

<CFBundle>
	<RedApp id="rest-comm-sabre-sample">
		<Authorization name="com.sabre.edge.cf.rest2sg.Rest2Sg">
			<Action name="/v4/lists/utilities/geocode/locations"
				threshold="1" />
		</Authorization>
		<Authorization name="com.sabre.edge.cf.rest2sg.Rest2Sg">
        	<Action name="/v1/lists/utilities/aircraft/equipment"
        		threshold="1" />
        </Authorization>
	</RedApp>
</CFBundle>

otherwise there will be an AUTH error response from 2SG.