CallFire API v2.0 Python SDK (beta)

Dependencies:

Project page

Getting started

Installation

Before start you should add dependency to your Python script:

  $ pip install callfire-api-client-python

Also you can find the latest bundle at releases page.

In case you want to build it yourself:

  $ git clone https://github.com/CallFire/callfire-api-client-python.git
  $ cd callfire-api-client-python
  $ pip install .

Overview

To create client instance just provide API login and password. API credentials should be configured on Account -> Settings -> API Access page. Client uses HTTPS connection and Basic Authentication.

The following example shows how to get an account information and send two SMS messages:

from callfire.client import CallfireClient
client = CallfireClient('api-login', 'api-password')

# get account info
response = client.me.getAccount().result()
print(response)

# send 2 SMSs
response = client.texts.sendTexts(
    # default message for recipients w/o TextRecipient.message field
    defaultMessage='Hello!',
    # specify a campaignId to send texts through a previously created campaign
    # campaignId: 4050600003
    body=[
        {
            'phoneNumber': '12135551122',
            'message': 'Hello World!'
        },
        # use an existing contact in CallFire account
        {'contactId': 122460000043},
        {
            'phoneNumber': '12135558090',
            'attributes': {
                'custom_external_id': 30005044,
                'custom_name': 'Alice'
            },
            'message': 'Hello, ${custom_name}!'
        },
    ]
).result()

print(response)

List of API groups:

    client = CallfireClient('api-login', 'api-password')
    client.calls.
    client.campaigns.
    client.contacts.
    client.keywords.
    client.me.
    client.media.
    client.numbers.
    client.orders.
    client.texts.
    client.webhooks.

Error handling

The CallFire Developers API uses standard HTTP response codes for responses. These HTTP codes indicate whether or not an API operation is successful.

Status Code 200 is the desired response code. A standard JSON response will follow.

Codes in the 400s range detail all of the errors a CallFire Developer could encounter while using the API. Bad Request, Rate Limit Reached, and Unauthorized are some of the sorts of responses in the 400s block.

Codes in the 500s range are error responses from the CallFire system. If an error has occurred anywhere in the execution of a resource that was not due to user input, a 500 response will be returned with a corresponding JSON error body. In that body will contain a message detailing what went wrong.

Getting access to the HTTP response

The default behavior for all API calls is to return API entities like:

from callfire.client import CallfireClient
client = CallfireClient('api-login', 'api-password')
account = client.me.getAccount().result()
print(account.email)

to get an access to HTTP response pass a 'also_return_response' config property set to True:

from callfire.client import CallfireClient
client = CallfireClient('api-login', 'api-password', {'also_return_response': True})

# get account info
account, http_response = client.me.getAccount().result()
print(account)
print(http_response)

Debug & logging

TBA