CSTA API Example

Here is an example of creating a session and receiving some monitor events with CSTA:

Create the session

Sent: <?xml version="1.0" encoding="UTF-8"?><StartApplicationSession xmlns="http://www.ecma-international.org/standards/ecma-354/appl_session/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><applicationInfo> <applicationID>My App</applicationID> <applicationSpecificInfo> <tns:SessionLoginInfo xmlns:tns="http://www.pbxnsip.com/schemas/csta/login"> <tns:userName>202</tns:userName> <tns:password>1234</tns:password> <tns:domain>sip.training.com</tns:domain> <tns:sessionCleanupDelay>60</tns:sessionCleanupDelay> </tns:SessionLoginInfo> </applicationSpecificInfo></applicationInfo><requestedProtocolVersions> <protocolVersion>http://www.ecma-international.org/standards/ecma-323/csta/ed3</protocolVersion> <protocolVersion>http://www.ecma-international.org/standards/ecma-323/csta/ed4</protocolVersion> <protocolVersion>http://www.ecma-international.org/standards/ecma-323/csta/ed5</protocolVersion></requestedProtocolVersions><requestedSessionDuration>1800</requestedSessionDuration></StartApplicationSession>

Received: '\x00\x00\x01\xc0l ve<?xml version="1.0" encoding="UTF-8"?><StartApplicationSessionPosResponse xmlns="http://www.ecma-international.org/standards/ecma-354/appl_session" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><sessionID>99bjucmahlernqjl55xx</sessionID><actualProtocolVersion>http://www.ecma-international.org/standards/ecma-323/csta/ed4</actualProtocolVersion><actualSessionDuration>180</actualSessionDuration></StartApplicationSessionPosResponse>'


Ask for monitor events

Sent: <?xml version="1.0" encoding="UTF-8"?><MonitorStart xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorObject><deviceObject>202@sip.training.com</deviceObject></monitorObject><monitorType>device</monitorType></MonitorStart>

Received: '\x00\x00\x01^l ve<?xml version="1.0" encoding="UTF-8"?><MonitorStartResponse xmlns="http://www.ecma-international.org/standards/ecma-354/appl_session" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><monitorCrossRefID>260368316</monitorCrossRefID><actualMonitorMediaClass><voice>true</voice><im>true</im></actualMonitorMediaClass></MonitorStartResponse>'


Receive monitor events

When the monitored extension makes a call, the server sends Monitor events:

Received: '\x00\x00\x01\xe29999<?xml version="1.0" encoding="UTF-8" ?><ServiceInitiatedEvent xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorCrossRefID>260368316</monitorCrossRefID><initiatedConnection><callID>25</callID><deviceID>202@sip.training.com</deviceID></initiatedConnection><initiatingDevice><deviceIdentifier>202@sip.training.com</deviceIdentifier></initiatingDevice><localConnectionInfo>initiated</localConnectionInfo><cause>normal</cause></ServiceInitiatedEvent>\x00\x00\x02(9999<?xml version="1.0" encoding="UTF-8" ?><OriginatedEvent xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorCrossRefID>260368316</monitorCrossRefID><originatedConnection><callID>25</callID><deviceID>202@sip.training.com</deviceID></originatedConnection><callingDevice><deviceIdentifier>202@sip.training.com</deviceIdentifier></callingDevice><calledDevice><deviceIdentifier>201@sip.training.com</deviceIdentifier></calledDevice><localConnectionInfo>connected</localConnectionInfo><cause>normal</cause></OriginatedEvent>\x00\x00\x02\xa79999<?xml version="1.0" encoding="UTF-8" ?><DeliveredEvent xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorCrossRefID>260368316</monitorCrossRefID><connection><callID>25</callID><deviceID>202@sip.training.com</deviceID></connection><alertingDevice><deviceIdentifier>201@sip.training.com</deviceIdentifier></alertingDevice><callingDevice><deviceIdentifier>202@sip.training.com</deviceIdentifier></callingDevice><calledDevice><deviceIdentifier>201@sip.training.com</deviceIdentifier></calledDevice><lastRedirectionDevice><notKnown /></lastRedirectionDevice><localConnectionInfo>connected</localConnectionInfo><cause>normal</cause></DeliveredEvent>'

Received: '\x00\x00\x02\xc39999<?xml version="1.0" encoding="UTF-8" ?><EstablishedEvent xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorCrossRefID>260368316</monitorCrossRefID><establishedConnection><callID>25</callID><deviceID>202@sip.training.com</deviceID></establishedConnection><answeringDevice><deviceIdentifier>201@sip.training.com</deviceIdentifier></answeringDevice><callingDevice><deviceIdentifier>202@sip.training.com</deviceIdentifier></callingDevice><calledDevice><deviceIdentifier>201@sip.training.com</deviceIdentifier></calledDevice><lastRedirectionDevice><notKnown /></lastRedirectionDevice><localConnectionInfo>connected</localConnectionInfo><cause>normal</cause></EstablishedEvent>'

Received: '\x00\x00\x01\xe19999<?xml version="1.0" encoding="UTF-8" ?><ConnectionClearedEvent xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorCrossRefID>260368316</monitorCrossRefID><droppedConnection><callID>25</callID><deviceID>202@sip.training.com</deviceID></droppedConnection><releasingDevice><deviceIdentifier>202@sip.training.com</deviceIdentifier></releasingDevice><localConnectionInfo>null</localConnectionInfo><cause>normalClearing</cause></ConnectionClearedEvent>'


Stop receiving monitor events

Sent: <?xml version="1.0" encoding="UTF-8"?><MonitorStop xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><monitorCrossRefID>260368316</monitorCrossRefID></MonitorStop>

Received: '\x00\x00\x00\xc5l ve<?xml version="1.0" encoding="UTF-8"?><MonitorStopResponse xmlns="http://www.ecma-international.org/standards/ecma-354/appl_session" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />'


Transfer a call

We assume extension 200 has called 202. Extension 200 wants to transfer the call to 302.
We will also need the call ID from 200's leg of the call, assume this is "ZWJjYzdiMDg2ZjAwM2VhZWM0OTJiMjk1OWJlMjIxMzA.". here is how we transfer:

Sent: <?xml version="1.0" encoding="UTF-8"?><SingleStepTransferCall xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"><transferredTo>302@10.10.21.233</transferredTo><activeCall><callID>ZWJjYzdiMDg2ZjAwM2VhZWM0OTJiMjk1OWJlMjIxMzA.</callID><deviceID>200@10.10.21.233</deviceID></activeCall></SingleStepTransferCall>

Received: '\x00\x00\x00\x95l ve<?xml version="1.0" encoding="UTF-8"?><SingleStepTransferCallResponse xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"/>'

End the session

Sent: <?xml version="1.0" encoding="UTF-8"><StopApplicationSession xmlns="http://www.ecma-international.org/standards/ecma-354/appl_session"><sessionID>99bjucmahlernqjl55xx</sessionID><sessionEndReason><definedEndReason>normal</definedEndReason></sessionEndReason></StopApplicationSession>

Received: '\x00\x00\x00\xd3l ve<?xml version="1.0" encoding="UTF-8"?><StopApplicationSessionPosResponse xmlns="http://www.ecma-international.org/standards/ecma-354/appl_session" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />'

Go to CSTA API