RingCentral Python Client library
Only Python 3.x is supported.
If you are having difficulty using this SDK, or working with the RingCentral API, please visit our developer community forums for help and to get quick answers to your questions. If you wish to contact the RingCentral Developer Support team directly, please submit a help ticket from our developer website.
pip install ringcentral_client
https://developer.ringcentral.com/api-docs/latest/index.html
from ringcentral_client import RestClient, SANDBOX_SERVER
rc = RestClient(clientId, clientSecret, SANDBOX_SERVER)
SANDBOX_SERVER
is a string constant for https://platform.devtest.ringcentral.com
.
from ringcentral_client import RestClient, PRODUCTION_SERVER
rc = RestClient(clientId, clientSecret, PRODUCTION_SERVER)
PRODUCTION_SERVER
is a string constant for https://platform.ringcentral.com
.
r = rc.authorize(username, extension, password)
print('authorized')
r = rc.refresh()
print('refreshed')
r = rc.revoke()
print('revoked')
If you want the SDK to refresh authorization automatically, you can rc.auto_refresh = True
.
If you do so, authorization is refreshed 2 minutes before it expires. Don't forget to call rc.revoke()
when you are done. Otherwise your app won't quit because there is a background timer running.
# GET
r = rc.get('/restapi/v1.0/account/~/extension/~')
print(r.text)
# POST
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', {
'to': [{'phoneNumber': receiver}],
'from': {'phoneNumber': username},
'text': 'Hello world'})
print(r.text)
# PUT
r = rc.get('/restapi/v1.0/account/~/extension/~/message-store', { 'direction': 'Outbound' })
message_id = r.json()['records'][0]['id']
r = rc.put('/restapi/v1.0/account/~/extension/~/message-store/{message_id}'.format(message_id = message_id),
{ 'readStatus': 'Read' })
print(r.text)
# DELETE
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', {
'to': [{ 'phoneNumber': receiver }],
'from': { 'phoneNumber': username },
'text': 'Hello world'})
message_id = r.json()['id']
r = rc.delete('/restapi/v1.0/account/~/extension/~/message-store/{message_id}'.format(message_id = message_id), { 'purge': False })
print(r.status_code)
with open(os.path.join(os.path.dirname(__file__), 'test.png'), 'rb') as image_file:
files = [
('json', ('request.json', json.dumps({ 'to': [{ 'phoneNumber': receiver }] }), 'application/json')),
('attachment', ('test.txt', 'Hello world', 'text/plain')),
('attachment', ('test.png', image_file, 'image/png')),
]
r = rc.post('/restapi/v1.0/account/~/extension/~/fax', files = files)
print(r.status_code)
params = {
'to': [{'phoneNumber': receiver}],
'from': {'phoneNumber': username},
'text': 'Hello world'
}
with open(os.path.join(os.path.dirname(__file__), 'test.png'), 'rb') as image_file:
files = [
('json', ('request.json', json.dumps(params), 'application/json')),
('attachment', ('test.png', image_file, 'image/png')),
]
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', params, files = files)
print(r.status_code)
# Upload
with open(os.path.join(os.path.dirname(__file__), 'test.png'), 'rb') as image_file:
files = {'image': ('test.png', image_file, 'image/png')}
r = rc.post('/restapi/v1.0/account/~/extension/~/profile-image', files = files)
# Download
r = rc.get('/restapi/v1.0/account/~/extension/~/profile-image')
# r.content is the downloaded binary
Please read the official documentation if you don't already know what is Authorization Code Flow.
uri = rc.authorize_uri('http://example.com/callback', 'state')
User will be prompted to login RingCentral and authorize your app.
If everything goes well, user will be redirect to http://example.com/callback?code=<auth_code>
.
http://example.com/callback?code=<auth_code>
Extract auth_code
from redirected url.
rc.authorize(auth_code = auth_code, redirect_uri = 'http://example.com/callback')
Please refer to the test cases.
For example, for voicemail MP3, you will get a content URL like the following in extension/message-store response:
https://media.ringcentral.com/restapi/v1.0/account/1111/extension/2222/message-store/3333/content/4444
You can add access token to the URL:
https://media.ringcentral.com/restapi/v1.0/account/1111/extension/2222/message-store/3333/content/4444?access_token=<theAccessToken>
This is mostly for embedding into sites like Glip temporarily or for sending to VoiceBase, etc.
MIT