Bandwidth Python API

Build Status Can I Use Python 3?

Full Reference

dev.bandwidth.com/python-bandwidth

github

Requirements

Installation

pip install bandwidth-sdk==2.0.0b0

Usage

Client Initialization

import bandwidth
api = bandwidth.client('catapult', 'u-user', 't-token', 's-secret')

Each of these code sample assumes that you have already initialized a client

Search and order phone number

numbers = api.search_available_local_numbers(area_code = '910', quantity = 3)
print(numbers[0]['number'])
## +19104440230

my_number = api.create_phone_number(numbers[0]['number'])

print(my_number)
#+19104440230

Send Text Message::

message_id = api.send_message(from_ = '+1234567980',
                              to = '+1234567981',
                              text = 'SMS message')
print(message_id)
# m-messageId

Send Picture Message::

message_id = api.send_message(from_ = '+1234567980',
                              to = '+1234567981',
                              text = 'MMS message',
                              media=['http://cat.com/cat.png'])
print(message_id)
# m-messageId

Fetch information about single message::

my_message = api.get_message('m-messageId')
print(my_message[state])
## received

Create an outbound call

call_id = api.create_call(from_ = '+1234567890',
                          to = '+1234567891',
                          callback_url = "http://yoursite.com/calls")
print(call_id)
## c-abc123

Get information on single call

my_call = api.get_call('c-abc123')
print(my_call)
## {   'callbackUrl'         : 'http://yoursite.com/calls',
##     'direction'           : 'out',
##     'events'              : 'https://api.catapult.inetwork.com/v1/users/u-abc/calls/c-abc123/events',
##     'from'                : '+1234567890',
##     'id'                  : 'c-abc123',
##     'recordingEnabled'    : False,
##     'recordingFileFormat' : 'wav',
##     'recordings'          : 'https://api.catapult.inetwork.com/v1/users/u-abc/calls/c-abc123/recordings',
##     'startTime'           : '2017-01-26T16:10:11Z',
##     'state'               : 'started',
##     'to'                  : '+1234567891',
##     'transcriptionEnabled': False,
##     'transcriptions'      : 'https://api.catapult.inetwork.com/v1/users/u-abc/calls/c-abc123/transcriptions'}

Retrieving list of calls

call_list = api.list_calls(to = '+19192223333', size = 2)
print(list(call_list))

results matching ""

    No results matching ""