Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated using 4PSA automated script

...

The example below demonstrates how you can use Unified API to connect two public numbers, not registered with VoipNow. It uses the Create Simple PhoneCalls request.

Code Block
languagepython
import httplib
import json

# Modify these values with the ones you intend to use
VN_SERVER_ADDRESS   = 'CHANGEME'
API_ACCESS_TOKEN    = 'CHANGEME'
EXTENSION_NUMBER    = 'CHANGEME'
PUBLIC_NUMBER1      = 'CHANGEME'
PUBLIC_NUMBER2      = 'CHANGEME'

# Setup the requests parameters
data = {
    "extension": EXTENSION_NUMBER,
    "phoneCallView" : [{
        "source" : PUBLIC_NUMBER1,
        "destination": PUBLIC_NUMBER2            
    }]
}

headers = {"Content-type": "application/json", "Authorization": "Bearer " + API_ACCESS_TOKEN}

# Makes a HTTP POST request using SSL
conn = httplib.HTTPSConnection(VN_SERVER_ADDRESS)
conn.request("POST", "/uapi/phoneCalls/@me/simple", json.dumps(data), headers)

# Parses the JSON response
response = conn.getresponse()
print json.dumps(json.loads(response.read()), indent=4) 

...

Code Block
languagepython
import httplib
import json

# Modify these values with the ones you intend to use
VN_SERVER_ADDRESS 	= 'CHANGEME'
API_ACCESS_TOKEN 	= 'CHANGEME'
EXTENSION_NUMBER    = 'CHANGEME'
SANDBOX_NUMBER 		= 'CHANGEME'

# Setup the requests parameters
data = {
	"extension": EXTENSION_NUMBER,
	"phoneCallView" : [{
		"source" : EXTENSION_NUMBER,
		"destination": SANDBOX_NUMBER			
	}]
}
headers = {"Content-type": "application/json", "Authorization": "Bearer " + API_ACCESS_TOKEN}

# Makes a HTTP POST request using SSL
conn = httplib.HTTPSConnection(VN_SERVER_ADDRESS)
conn.request("POST", "/uapi/phoneCalls/@me/simple", json.dumps(data), headers)

# Parses the JSON response
response = json.loads(conn.getresponse().read())
print json.dumps(response, indent=4)

...

The example below demonstrates how you can use Unified API to park a party of an ongoing phone call. It uses the the Park PhoneCalls request.

Code Block
languagepython
'''
4PSA VoipNow UnifiedAPI Example: Phone Call Parking
This script will transfer a public phone call.
@version 1.0.0
@license released under GNU General Public License
@copyright (c) 2013 4PSA. (www.4psa.com). All rights reserved.
@link http://wiki.4psa.com
'''
import httplib
import json
# Modify these values with the ones you intend to use
VN_SERVER_ADDRESS       = 'CHANGEME'
API_ACCESS_TOKEN        = 'CHANGEME'
PHONECALL_ID            = 'CHANGEME'
PHONECALLVIEW_ID        = 'CHANGEME'
# Setup the requests parameters
data = {
    'action': 'Park',
    'phoneCallViewId': PHONECALLVIEW_ID
}
headers = {"Content-type": "application/json", "Authorization": "Bearer " + API_ACCESS_TOKEN}
# Makes a HTTP PUT request using SSL
conn = httplib.HTTPSConnection(VN_SERVER_ADDRESS)
conn.request("PUT", "/unifiedapi/phoneCalls/@me/@self/"+PHONECALL_ID, json.dumps(data), headers)
# Parses the JSON response
response = conn.getresponse()
print json.dumps(json.loads(response.read()), indent=4)

...

The example below demonstrates how you can use Unified API to transfer a call to a public number, not registered with VoipNow. It uses the the Transfer PhoneCalls request.

...

The example below demonstrates how you can use Unified API to record an ongoing conversation. This action is possible for phone numbers that are registered with VoipNow. The recording is saved in the the wav format and uses the StartRecording PhoneCalls request.

...

Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 4.0 International.