Giter Club home page Giter Club logo

apiclient-python's Introduction

Voximplant API client library

Version 1.11.0

Prerequisites

In order to use the Voximplant Python SDK, you need the following:

  1. A developer account. If you don't have one, sign up here.
  2. A private API key. There are 2 options to obtain it:
    1. Either generate it in the Voximplant Control panel
    2. Or call the CreateKey HTTP API method with the specified authentication parameters. You'll receive a response with the result field in it. Save the result value in a file (since we don't store the keys, save it securely on your side).
  3. Python 2.x or 3.x runtime with pip and setuptools>=18.5 installed

How to use

Go to your project folder and install the SDK using pip:

python -m pip install --user voximplant-apiclient

Then import the SDK in your script

from voximplant.apiclient import VoximplantAPI

Next, specify the path to the JSON service account file either in the constructor or using the environment.

constructor:

api = VoximplantAPI("/path/to/credentials.json")

env:

export VOXIMPLANT_CREDENTIALS=/path/to/credentials.json

Examples

Start a scenario

from voximplant.apiclient import VoximplantAPI, VoximplantException

if __name__ == "__main__":
    api = VoximplantAPI("credentials.json")

    # Start a scenario of the user 1

    RULE_ID = 1
    SCRIPT_CUSTOM_DATA = "mystr"
    USER_ID = 1

    try:
        res = api.start_scenarios(RULE_ID, script_custom_data=SCRIPT_CUSTOM_DATA, user_id=USER_ID)
        print(res)
    except VoximplantException as e:
        print("Error: {}".format(e.message))

Send an SMS

from voximplant.apiclient import VoximplantAPI, VoximplantException

if __name__ == "__main__":
    api = VoximplantAPI("credentials.json")

    # Send the SMS with the "Test message" text from the phone number 447443332211 to the phone number 447443332212

    SOURCE = "447443332211"
    DESTINATION = "447443332212"
    SMS_BODY = "Test message"

    try:
        res = api.send_sms_message(SOURCE, DESTINATION, SMS_BODY)
        print(res)
    except VoximplantException as e:
        print("Error: {}".format(e.message))

Get a call history item

from voximplant.apiclient import VoximplantAPI, VoximplantException
import pytz
import datetime

if __name__ == "__main__":
    api = VoximplantAPI("credentials.json")

    # Get the first call session history record from the 2012-01-01 00:00:00 UTC to the 2014-01-01 00:00:00 UTC

    FROM_DATE = datetime.datetime(2012, 1, 1, 0, 0, 0, pytz.utc)
    TO_DATE = datetime.datetime(2014, 1, 1, 0, 0, 0, pytz.utc)
    COUNT = 1

    try:
        res = api.get_call_history(FROM_DATE, TO_DATE, count=COUNT)
        print(res)
    except VoximplantException as e:
        print("Error: {}".format(e.message))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.