A2Billing Flask API Documentation - Read the Docs · 2019-04-02 · A2Billing Flask API...
Transcript of A2Billing Flask API Documentation - Read the Docs · 2019-04-02 · A2Billing Flask API...
A2Billing Flask API DocumentationRelease 10
Areski Belaid
Mar 14 2017
Contents
1 Overview 311 Installation 312 Requirements 313 Admin Panel 414 Stress Test 415 Install amp Deployment 416 Security 417 Create an Admin User 518 Documentation 519 Contributing 5110 License 5
2 List of APIs 721 CardGroup - Method [GETPOSTPUTDELETE] 722 Card - Method [GETPOSTPUTDELETE] 823 Call - Method [GETPOSTPUTDELETE] 824 CallerID - Method [GETPOSTPUTDELETE] 925 LogRefill - Method [GETPOSTPUTDELETE] 1026 LogPayment - Method [GETPOSTPUTDELETE] 1027 Country - Method [GETPOSTPUTDELETE] 1128 Refill - Method [POST] 1129 Extra Charge - Method [POST] 12
3 APIs Detailed Documentation 1331 Usage API - Card 1332 Usage API - Card Group 1633 Usage API - Callerid 1834 Usage API - Logrefill 2035 Usage API - Logpayment 2136 Usage API - Call 2237 Usage API - Country 2338 Usage API - Refill 2439 Usage API - Extra Charge 25
4 Deploy A2Billing-Flask-API 2741 Installing mod_wsgi 2742 WSGI Application 27
i
43 Configuring Apache 27
5 Resources 2951 Extra tools 29
6 Indices and tables 31
ii
A2Billing Flask API Documentation Release 10
Contents
Contents 1
A2Billing Flask API Documentation Release 10
2 Contents
CHAPTER 1
Overview
Source httpsgithubcomareskia2billing-flask-api
Keywords a2billing api flask
Flexible amp Fast Restful APIs framework for A2Billing powered by Flask amp Peewee A2Billing-Flask-API comes withsome tools for exposing your A2Billing models via a RESTful API
Each RestFul APIs exposed supports the following
apiltmodel namegt ndash GET and POST requests
apiltmodel namegtltprimary keygt ndash GET PUT and DELETE requests
Also you can filter results by columns on the model For example
apicardgroupname=Some20Blog
_installation
Installation
An install shell script is provided at httpsgithubcomareskia2billing-flask-apitreemasterinstall
The install script is intended to run on Debian 8
Usage
wget httpsrawgithubusercontentcomareskia2billing-flask-apimasterinstallrarr˓install-a2b-flask-apishbash install-a2b-flask-apish
Requirements
This Application is build using Flask and Peewee
3
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
Contents
1 Overview 311 Installation 312 Requirements 313 Admin Panel 414 Stress Test 415 Install amp Deployment 416 Security 417 Create an Admin User 518 Documentation 519 Contributing 5110 License 5
2 List of APIs 721 CardGroup - Method [GETPOSTPUTDELETE] 722 Card - Method [GETPOSTPUTDELETE] 823 Call - Method [GETPOSTPUTDELETE] 824 CallerID - Method [GETPOSTPUTDELETE] 925 LogRefill - Method [GETPOSTPUTDELETE] 1026 LogPayment - Method [GETPOSTPUTDELETE] 1027 Country - Method [GETPOSTPUTDELETE] 1128 Refill - Method [POST] 1129 Extra Charge - Method [POST] 12
3 APIs Detailed Documentation 1331 Usage API - Card 1332 Usage API - Card Group 1633 Usage API - Callerid 1834 Usage API - Logrefill 2035 Usage API - Logpayment 2136 Usage API - Call 2237 Usage API - Country 2338 Usage API - Refill 2439 Usage API - Extra Charge 25
4 Deploy A2Billing-Flask-API 2741 Installing mod_wsgi 2742 WSGI Application 27
i
43 Configuring Apache 27
5 Resources 2951 Extra tools 29
6 Indices and tables 31
ii
A2Billing Flask API Documentation Release 10
Contents
Contents 1
A2Billing Flask API Documentation Release 10
2 Contents
CHAPTER 1
Overview
Source httpsgithubcomareskia2billing-flask-api
Keywords a2billing api flask
Flexible amp Fast Restful APIs framework for A2Billing powered by Flask amp Peewee A2Billing-Flask-API comes withsome tools for exposing your A2Billing models via a RESTful API
Each RestFul APIs exposed supports the following
apiltmodel namegt ndash GET and POST requests
apiltmodel namegtltprimary keygt ndash GET PUT and DELETE requests
Also you can filter results by columns on the model For example
apicardgroupname=Some20Blog
_installation
Installation
An install shell script is provided at httpsgithubcomareskia2billing-flask-apitreemasterinstall
The install script is intended to run on Debian 8
Usage
wget httpsrawgithubusercontentcomareskia2billing-flask-apimasterinstallrarr˓install-a2b-flask-apishbash install-a2b-flask-apish
Requirements
This Application is build using Flask and Peewee
3
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
43 Configuring Apache 27
5 Resources 2951 Extra tools 29
6 Indices and tables 31
ii
A2Billing Flask API Documentation Release 10
Contents
Contents 1
A2Billing Flask API Documentation Release 10
2 Contents
CHAPTER 1
Overview
Source httpsgithubcomareskia2billing-flask-api
Keywords a2billing api flask
Flexible amp Fast Restful APIs framework for A2Billing powered by Flask amp Peewee A2Billing-Flask-API comes withsome tools for exposing your A2Billing models via a RESTful API
Each RestFul APIs exposed supports the following
apiltmodel namegt ndash GET and POST requests
apiltmodel namegtltprimary keygt ndash GET PUT and DELETE requests
Also you can filter results by columns on the model For example
apicardgroupname=Some20Blog
_installation
Installation
An install shell script is provided at httpsgithubcomareskia2billing-flask-apitreemasterinstall
The install script is intended to run on Debian 8
Usage
wget httpsrawgithubusercontentcomareskia2billing-flask-apimasterinstallrarr˓install-a2b-flask-apishbash install-a2b-flask-apish
Requirements
This Application is build using Flask and Peewee
3
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
Contents
Contents 1
A2Billing Flask API Documentation Release 10
2 Contents
CHAPTER 1
Overview
Source httpsgithubcomareskia2billing-flask-api
Keywords a2billing api flask
Flexible amp Fast Restful APIs framework for A2Billing powered by Flask amp Peewee A2Billing-Flask-API comes withsome tools for exposing your A2Billing models via a RESTful API
Each RestFul APIs exposed supports the following
apiltmodel namegt ndash GET and POST requests
apiltmodel namegtltprimary keygt ndash GET PUT and DELETE requests
Also you can filter results by columns on the model For example
apicardgroupname=Some20Blog
_installation
Installation
An install shell script is provided at httpsgithubcomareskia2billing-flask-apitreemasterinstall
The install script is intended to run on Debian 8
Usage
wget httpsrawgithubusercontentcomareskia2billing-flask-apimasterinstallrarr˓install-a2b-flask-apishbash install-a2b-flask-apish
Requirements
This Application is build using Flask and Peewee
3
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
2 Contents
CHAPTER 1
Overview
Source httpsgithubcomareskia2billing-flask-api
Keywords a2billing api flask
Flexible amp Fast Restful APIs framework for A2Billing powered by Flask amp Peewee A2Billing-Flask-API comes withsome tools for exposing your A2Billing models via a RESTful API
Each RestFul APIs exposed supports the following
apiltmodel namegt ndash GET and POST requests
apiltmodel namegtltprimary keygt ndash GET PUT and DELETE requests
Also you can filter results by columns on the model For example
apicardgroupname=Some20Blog
_installation
Installation
An install shell script is provided at httpsgithubcomareskia2billing-flask-apitreemasterinstall
The install script is intended to run on Debian 8
Usage
wget httpsrawgithubusercontentcomareskia2billing-flask-apimasterinstallrarr˓install-a2b-flask-apishbash install-a2b-flask-apish
Requirements
This Application is build using Flask and Peewee
3
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
CHAPTER 1
Overview
Source httpsgithubcomareskia2billing-flask-api
Keywords a2billing api flask
Flexible amp Fast Restful APIs framework for A2Billing powered by Flask amp Peewee A2Billing-Flask-API comes withsome tools for exposing your A2Billing models via a RESTful API
Each RestFul APIs exposed supports the following
apiltmodel namegt ndash GET and POST requests
apiltmodel namegtltprimary keygt ndash GET PUT and DELETE requests
Also you can filter results by columns on the model For example
apicardgroupname=Some20Blog
_installation
Installation
An install shell script is provided at httpsgithubcomareskia2billing-flask-apitreemasterinstall
The install script is intended to run on Debian 8
Usage
wget httpsrawgithubusercontentcomareskia2billing-flask-apimasterinstallrarr˓install-a2b-flask-apishbash install-a2b-flask-apish
Requirements
This Application is build using Flask and Peewee
3
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
bull Python 25 or greater
bull Flask httpflaskpocooorg
bull Peewee httppeeweereadthedocsorgenlatest
bull Gunicorn httpgunicornorg
bull WTForms httpwtformsreadthedocsorgenlatest
bull MySQL-python MySQL-python
bull Flask-HTTPAuth httpspypipythonorgpypiFlask-HTTPAuth
See the file requirementstxt for the full list of requirements
_admin-panel
Admin Panel
An Admin Panel is provided which can be accessed at httpltip_addressgt8008admin
You will need an admin username and password to login see the section below on how to create an admin user
View resources
Edit resources
Stress Test
Use ab the Apache HTTP server benchmarking tool
Usage
ab -c 100 -n 1000 -p testposttxt -T applicationx-www-form-urlencoded httprarr˓localhost8008apicardgroup
Install amp Deployment
There are many ways to deploy a Flask Application we will describe the Apache Method here as this is the one moresuitable for A2Billing users
Reference httpswwwdigitaloceancomcommunityarticleshow-to-deploy-a-flask-application-on-an-ubuntu-vps
Security
Edit a2billing_flaskapipy and change the secret key and keep this really secret
appsecret_key = ssshhhh-and-changeme-when-deploying
4 Chapter 1 Overview
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
Create an Admin User
We now have a functioning admin site you can login with user password admin admin
Change immediately the default password by a strong password
You might want to create an other admin user from shell to do so open up an interactive python shell in the directoryalongside the app and run the following
$ cd usrsharea2billing-flask-api$ workon a2billing-flask-api$ python
Then in Python interpreter type the following
from a2billing_flask_api import authauthUsercreate_table(fail_silently=True) make sure table createdadmin = authUser(username=admin email= admin=True active=True)adminset_password(admin)adminsave()
Documentation
Check out the documentation on lsquoRead the Docsrsquo httpa2billing-flask-apireadthedocsorgenlatestindexhtml
Contributing
If yoursquove found a bug add a feature or improve the project and think it is useful then please consider contributingPatches pull requests or just suggestions are always welcome
Source code httpsgithubcomareskia2billing-flask-api
If you donrsquot like Github and Git yoursquore welcome to send regular patches
Bug tracker httpsgithubcomareskia2billing-flask-apiissues
License
A2Billing-Flask-API is licensed under MPLv2
17 Create an Admin User 5
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
6 Chapter 1 Overview
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
CHAPTER 2
List of APIs
This is the list of Restful APIs supported
CardGroup - Method [GETPOSTPUTDELETE]
Get list of card-groups create new card-group UpdateDelete existing card-group
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicardgroup
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardgroupname=DEFAULT
GET ONE
curl -u usernamepassword httplocalhost8008apicardgroup1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicardgroup4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicardgroup
UPDATE
7
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓cardgroup3
Card - Method [GETPOSTPUTDELETE]
Get list of cards create new card UpdateDelete existing card
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicard
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicardusername=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicard1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicard4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data name mygroup description httplocalhost8008apicard
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data name mygroup-updated description httplocalhost8008apirarr˓card3
Call - Method [GETPOSTPUTDELETE]
Get list of calls create new calls UpdateDelete existing calls
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicall
GET ALL FILTER
8 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
curl -u usernamepassword httplocalhost8008apicallfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicall1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicall4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicall
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicall3
CallerID - Method [GETPOSTPUTDELETE]
Get list of CallerIds create new CallerIds UpdateDelete existing CallerIds
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicallerid
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicalleridfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicallerid1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicallerid4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicallerid
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicallerid3
24 CallerID - Method [GETPOSTPUTDELETE] 9
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
LogRefill - Method [GETPOSTPUTDELETE]
Get list of Refills create new Refills UpdateDelete existing Refills
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogrefill
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogrefillfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogrefill1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogrefill4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogrefill
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogrefill3
LogPayment - Method [GETPOSTPUTDELETE]
Get list of Payments create new Payments UpdateDelete existing Payments
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apilogpayment
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apilogpaymentfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apilogpayment1
DELETE
10 Chapter 2 List of APIs
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apilogpayment4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apilogpayment
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apilogpayment3
Country - Method [GETPOSTPUTDELETE]
Get list of Countries create new Countries UpdateDelete existing Countries
METHODS
GET ALL
curl -u usernamepassword httplocalhost8008apicountry
GET ALL FILTER
curl -u usernamepassword httplocalhost8008apicountryfield=1321546
GET ONE
curl -u usernamepassword httplocalhost8008apicountry1
DELETE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -Xrarr˓DELETE httplocalhost8008apicountry4
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data httplocalhost8008apicountry
UPDATE
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X PUT --rarr˓data httplocalhost8008apicountry3
Refill - Method [POST]
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
27 Country - Method [GETPOSTPUTDELETE] 11
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data credit 5 httplocalhost8008custom_apirefill1
Extra Charge - Method [POST]
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
METHODS
ADD
curl -u usernamepassword --dump-header - -H Content-Typeapplicationjson -X POST -rarr˓-data amount 5 httplocalhost8008custom_apiextra_charge1
12 Chapter 2 List of APIs
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
CHAPTER 3
APIs Detailed Documentation
Usage API - Card
Cards are A2Billing Users on the A2Billing Platform this regroups credentials and specific information related to theusers such as names address balance etc
GET ALL
$ curl -u usernamepassword httplocalhost8008apicard
Result
meta
model cardnext page 1previous
objects [
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0
13
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicard1
Result
email_notification areskigmailcomstatus 1expiredays nullloginkey 4654lock_pin 0useralias 312224525577965uipass 18314euvyzix7spr1eewactivated fcurrency USDtag okinitialbalance 00voicemail_activated 0redial 0id 1sip_buddy 1city Barcelonaid_group 1
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicard4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 185043 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquousernamerdquoldquo1234567890rdquo ldquouseraliasrdquo ldquo0554654648rdquo ldquolastnamerdquo ldquoBelaidrdquo ldquofirstnamerdquo ldquoAreskirdquo ldquouipassrdquo ldquo6546456rdquoldquocreditrdquo ldquo5rdquo ldquotariffrdquo ldquo1rdquorsquo httplocalhost8008apicard
14 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1257Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233314 GMT
email_notification status 1expiredays nullloginkey lock_pin nulluseralias 0554654648uipass 6546456activated nullcurrency USDtag initialbalance 00voicemail_activated 0redial id 7sip_buddy 0city id_group 1notify_email 0
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquolastnamerdquo ldquoBe-laidrdquorsquo httplocalhost8008apicard7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 1290Server Werkzeug094 Python275+Date Thu 17 Apr 2014 233610 GMT
email_notification status 1expiredays loginkey lock_pin nulluseralias 0554654648uipass 6546456activated fcurrency USDtag initialbalance 00voicemail_activated 0redial
31 Usage API - Card 15
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
id 7sip_buddy 0city id_group 1notify_email 0
Usage API - Card Group
Card Group allows to regroup Card per entity and define agents associated to them as well as user permissions whenaccessing the Customer UI
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta
model cardgroupnext page 1previous
objects [
id_agent nulldescription This group is the default group used when you create a
rarr˓customer Its forbidden to delete it because you need at least one group but yourarr˓can edit it
users_perms 262142id 1name DEFAULT
id_agent 0description nullusers_perms 0id 2name NewGroup
]
GET ONE
$ curl -u usernamepassword httplocalhost8008apicardgroup1
Result
16 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
id_agent nulldescription This group is the default group used when you create a customer
rarr˓Its forbidden to delete it because you need at least one group but you can edit itrarr˓
users_perms 262142id 1name DEFAULT
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicardgroup4
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161103 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquonamerdquo ldquomy-grouprdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 96Server Werkzeug094 Python275+Date Thu 17 Apr 2014 160855 GMT
id_agent 0description users_perms 0id 3name mygroup
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquonamerdquo ldquomygroup-updatedrdquo ldquodescriptionrdquo ldquordquorsquo httplocalhost8008apicardgroup3
Result
32 Usage API - Card Group 17
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
HTTP10 200 OKContent-Type applicationjsonContent-Length 104Server Werkzeug094 Python275+Date Thu 17 Apr 2014 161231 GMT
id_agent 0description users_perms 0id 3name mygroup-updated
Usage API - Callerid
This entity is the CallerIDs associated to a customer (Card)
GET ALL
$ curl -u usernamepassword httplocalhost8008apicardgroup
Result
meta model calleridnext page 1previous
objects [
id_cc_card 1activated tid 2cid 45454565456456
]
GET ONE
$ curl -i -u usernamepassword httplocalhost8008apicardgroup1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 79Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212756 GMT
18 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
id_cc_card 1activated tid 2cid 45454565456456
DELETE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X DELETEhttplocalhost8008apicallerid6
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 18Server Werkzeug0112 Python279Date Fri 27 Nov 2015 212918 GMT
deleted 1
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoid_cc_cardrdquo 1ldquocidrdquo ldquo9501234657rdquorsquo httplocalhost8008apicallerid
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213119 GMT
id_cc_card 1activated tid 7cid 9501234657
UPDATE
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X PUT ndashdata lsquoldquocidrdquoldquo9501234658rdquorsquo httplocalhost8008apicallerid7
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 75
33 Usage API - Callerid 19
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
Server Werkzeug0112 Python279Date Fri 27 Nov 2015 213230 GMT
id_cc_card 1activated tid 7cid 9501234658
Usage API - Logrefill
This is used to track the refill made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogrefill
Result
meta model logrefillnext page 1previous
objects [
description CREATION CARD REFILLrefill_type 0agent nullcredit 500000date 2014-04-16 011145id 1card 1added_invoice 0
description 4654refill_type 0agent nullcredit 645600000date 2014-06-04 145636id 2card 1added_invoice 0
]
20 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Logpayment
This is used to track the payment made into the A2Billing platform
GET ALL
$ curl -u usernamepassword httplocalhost8008apilogpayment
Result
meta model logpaymentnext page 1previous
objects [
added_refill 1description 4654added_commission 0id 1payment_type 2agent nulldate 2014-06-04 145636id_logrefill 2payment 645600000card 1
added_refill 0description nulladded_commission 0id 2
35 Usage API - Logpayment 21
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
payment_type 0agent nulldate nullid_logrefill 12payment 589000card 2
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Call
This entity is the Call also known as CDR
GET ALL
$ curl -u usernamepassword httplocalhost8008apicall
Result
meta model callnext page 1previous
objects [
calledstation 7987944994id_did 0id_tariffplan 1id 1
22 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
id_ratecard 1terminatecauseid 5destination 132487987dnid 61984644starttime 2015-11-27 223602id_card_package_offer 0nasipaddress 127001id_trunk 2sipiax nullsessionid 13564654984stoptime nullsessiontime 40uniqueid 654654981615src sourcebuycost 010000card_id 1id_tariffgroup 2real_sessiontime 50sessionbill 400
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Country
List of countries
GET ALL
$ curl -u usernamepassword httplocalhost8008apicountry
Result
37 Usage API - Country 23
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
meta model countrynext apicountrypage=2page 1previous
objects [
countryname Afghanistanid 1countrycode AFGcountryprefix 93
countryname Albaniaid 2countrycode ALBcountryprefix 355
]
GET ONE
TODO Not documented
DELETE
TODO Not documented
ADD
TODO Not documented
UPDATE
TODO Not documented
Usage API - Refill
This API will refill an AccountCard for a given credit amount (value Decimal) A logpayment and a logrefill willalso be added to log the refill
In the result the current balance will be returned with the VATTax from the AccountCard and the created logpaymentID and logrefill Id will also be returned
24 Chapter 3 APIs Detailed Documentation
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquocreditrdquo 5rsquohttplocalhost8008custom_apirefill1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 169Server Werkzeug0112 Python279Date Fri 27 Nov 2015 220431 GMT
card_id 1credit_without_vat 50credited 50current_balance 65110logpayment_id 9logrefill_id 19vat 0
Usage API - Extra Charge
This API will decrement an AccountCard for a given amount (value Decimal) then a charge will also be added tolog the transaction
In the result the current balance will be returned and the created Charge Id will also be returned
ADD
$ curl -u usernamepassword ndashdump-header - -H ldquoContent-Typeapplicationjsonrdquo -X POST ndashdata lsquoldquoamountrdquo 5rsquohttplocalhost8008custom_apiextra_charge1
Result
HTTP10 200 OKContent-Type applicationjsonContent-Length 82Server Werkzeug0112 Python279Date Fri 27 Nov 2015 224636 GMT
amount 50card_id 1charge_id 8current_balance 64960
39 Usage API - Extra Charge 25
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
26 Chapter 3 APIs Detailed Documentation
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
CHAPTER 4
Deploy A2Billing-Flask-API
There are many ways to deploy a Flask application here we will focus on deploying on Apache2 webserver usingmod_wsgi This should be the easiest way for A2Billing users without installing too many applications on their server
Installing mod_wsgi
If you donrsquot have mod_wsgi installed yet you have to either install it using a package manager or compile it yourself
If you are using UbuntuDebian you can apt-get it and activate it as follows
apt-get install libapache2-mod-wsgi
WSGI Application
To run your application you need an appwsgi file Mod_wsgi is executing this file on startup to get the applicationobject
The a2billing_flask_appwsgi is located at the root of this repository
Configuring Apache
The last thing to do is to create an Apache configuration file for your application
Apache config
ltVirtualHost gtServerName examplecom
WSGIDaemonProcess a2billing_flask_app user=user1 group=group1 threads=5WSGIScriptAlias usrsharea2billing-flask-apia2billing_flask_appwsgi
27
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
ltDirectory usrsharea2billing-flask-apigtWSGIProcessGroup a2billing_flask_appWSGIApplicationGroup GLOBALOrder denyallowAllow from all
ltDirectorygtltVirtualHostgt
28 Chapter 4 Deploy A2Billing-Flask-API
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
CHAPTER 5
Resources
Extra tools
bull pwiz a model generator
pwiz is a little script that ships with peewee and is capable of introspecting an existing databaseand generating model code suitable for interacting with the underlying data If you have a databasealready pwiz can give you a nice boost by generating skeleton code with correct column affinitiesand foreign keys
Documentation httpdocspeewee-ormcomenlatestpeeweeplayhousehtmlpwiz-a-model-generator
29
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
A2Billing Flask API Documentation Release 10
30 Chapter 5 Resources
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-
CHAPTER 6
Indices and tables
bull genindex
bull modindex
bull search
31
- Overview
-
- Installation
- Requirements
- Admin Panel
- Stress Test
- Install amp Deployment
- Security
- Create an Admin User
- Documentation
- Contributing
- License
-
- List of APIs
-
- CardGroup - Method [GETPOSTPUTDELETE]
- Card - Method [GETPOSTPUTDELETE]
- Call - Method [GETPOSTPUTDELETE]
- CallerID - Method [GETPOSTPUTDELETE]
- LogRefill - Method [GETPOSTPUTDELETE]
- LogPayment - Method [GETPOSTPUTDELETE]
- Country - Method [GETPOSTPUTDELETE]
- Refill - Method [POST]
- Extra Charge - Method [POST]
-
- APIs Detailed Documentation
-
- Usage API - Card
- Usage API - Card Group
- Usage API - Callerid
- Usage API - Logrefill
- Usage API - Logpayment
- Usage API - Call
- Usage API - Country
- Usage API - Refill
- Usage API - Extra Charge
-
- Deploy A2Billing-Flask-API
-
- Installing mod_wsgi
- WSGI Application
- Configuring Apache
-
- Resources
-
- Extra tools
-
- Indices and tables
-