Skip to main content

osaAPI

pyversions Build Status PyPi Status

A python binding for the CloudBlue Commerce APIs a.k.a. Odin Service Automation or OSA.

Installation

Using pip:

$ pip install osaAPI

Connecting and Authenticating

OSA(host,user=None,password=None,ssl=False,verbose=False,port=8440)

PBA(host,user=None,password=None,ssl=False,verbose=False,port=5224)

Default Connection

from osaapi import OSA, PBA

# connect to OSA
pem = OSA('mn.hostname.com')

# connect to PBA
api = PBA('pba.hostname.com')

Basic HTTP Authentication

from osaapi import OSA, PBA

# connect to OSA 
pem = OSA('mn.hostname.com', user='admin', password='setup')

SSL

from osaapi import OSA, PBA

# connect to OSA 
pem = OSA('mn.hostname.com', ssl=True)

Custom Port

from osaapi import OSA, PBA

# connect to OSA 
pem = OSA('mn.hostname.com', port=8888)

CloudBlue Commerce API

All but three of the OSA API calls start with 'pem', for this reason it is recommended you name your OSA connection object 'pem' so you can call functions exactly how they are documented in the OSA API as has been done in the examples in this Readme.

The full OSA Public API Reference can be found here:

http://download.automation.odin.com/oa/7.1/oapremium/portal/en/operations_api_reference/index.htm?fileName=about.htm

Basic API Call

This example will show the pem.getAccountInfo method being called.

from osaapi import OSA

pem = OSA('mn.hostname.com')

d = {
    'account_id' : 1002242
}

print pem.getAccountInfo(**d)

# {'status': 0, 'result': {'fax': {'phone_num': '', 'ext_num': '', 'area_code': '', 'country_code': ''}, 'account_type': 'C', 'phone': {'phone_num': '00000000', 'ext_num': '', 'area_code': '04', 'country_code': '61'}, 'brand': {'brand_id': 191, 'domain_name': 'brandingdomain.com', 'name': 'brandname'}, 'email': 'noreply@example.com', 'person': {'first_name': 'John', 'last_name': 'Smith', 'middle_name': '', 'company_name': 'Test Account', 'title': ''}, 'address': {'city': 'Canberra', 'country': 'au', 'street_name': '1 Test Street', 'zipcode': '2621', 'state': 'ACT', 'house_num': '', 'address2': ''}, 'parent_account_id': 1002241}}

API Call with 'array of struct'

The OSA API often calls for values and settings to be sent as an 'array of struct'. This example shows how to send these values using the osaapi client.

This example is based on the pem.activateSubscription method with resources types called 'DiskSpace' and 'Bandwidth' and a domain name.

from osaapi import OSA

pem = OSA('mn.hostname.com')

# define the resource limits:
DiskSpace = {
    "resource_id" : 1002486,
    "resource_limit" : 1024
}
Bandwidth = {
    "resource_id" : 1002487,
    "resource_limit" : -1
}

# define the paramaters:
DomainName = {
    "var_name"  : "DomainID",
    "var_value" : "example.com.au"
}

# setup the call:
d = {
    "account_id"           : 1002242,
    "subscription_name"    : "Hosting (example.com.au)",
    "subscription_id"      : 1006754,
    "service_template_id"  : 204,
    "resource_limits"      : [DiskSpace, Bandwidth],
    "paramaters"           : [DomainName],
}

# execute the call:
result = pem.activateSubscription(**d)

Transactions

http://download.automation.odin.com/oa/7.1/oapremium/portal/en/operations_api_reference/43326.htm

There are three OSA API calls that do not start with pem in the official documentation. When using osaapi you can use these API calls as documented but you will still need to prefix them with your OSA connection object (the examples on this page use 'pem' as the connection object name).

from osaapi import OSA

pem = OSA('mn.hostname.com')

# being transaction
pem.txn.Begin()

# commit transaction
pem.txn.Commit()

# rollback transaction
pem.txn.Rollback()

Error Handling

The OSA API has quite good responses when an error occurs during an API call. The below example shows the response format for OSA API errors:

{
    'status'         : -1, 
    'extype_id'      : 21, 
    'module_id'      : 'OpenAPI', 
    'error_message'  : 'Invalid set of arguments. There should be specified EITHER external_info OR person, address, phone, [fax], [locale], email.', 
    'properties'     : { 
                           'reason': 'Invalid set of arguments. There should be specified EITHER external_info OR person, address, phone, [fax], [locale], email.'
                       }
}

Billing module API

The billing API is quite different from the OSA API, and not quite as user friendly. The osaapi client makes using the billing a little easier by standardizing the returned responses, providing status codes, and decoding any error messages.

The major difference between the OSA and billing api is how values are sent and received. In billing params are sent and responses are received as a list in a specific order to know what each value represents.

The full billing Public API Reference can be found here:

http://download.automation.odin.com/oa/7.1/oapremium/portal/en/billing_api_reference/74975.htm

Basic API Call

This example will show the AccountDetailsGet_API method being called.

from osaapi import PBA

api = PBA('pba.hostname.com')

print api.Execute('AccountDetailsGet_API', params=['1002242'])

# {'status': 0, 'result': [1002242, 1002241, 'Test Account  5543', '1 Test Street', '', 'Canberra', '', '2621', 'au', '', 'John', 'D', 'Smith', 'noreply@example.com', '61', '04', '000000000', '', '', '', '', '', 1351787114, 2, 0]}

Alternate Server

Most billing API method calls use the "BM" server. Some methods use alternate servers such as "PEMGATE" or "DOMAINGATE". This example shows how to specify an alternate server:

from osaapi import PBA

api = PBA('pba.hostname.com')

api.Execute('DomainExpirationDateGet_API', params=params, server='DOMAINGATE')

Error Handling

osaapi takes the way OSA returns errors natively and applies it to the billing API. The status on each responce will either be 0 for a succesfull call, or -1 if billing returned an error.

This is an example of what is returned in the case of an error:

{
    'status'        : -1, 
    'error_message' : 'Table Account does not contain row with ID 99999999.', 
    'server'        : 'BM', 
    'host'          : 'pba.hostname.com', 
    'params'        : ['99999999'], 
    'result'        : None, 
    'method'        : 'AccountDetailsGet_API'
}

Metadata

Release files for osaapi 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osaapi 1.0.1
File Size Uploaded
osaapi-1.0.1.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osaapi 1.0.1
File Interpreter ABI Platform
osaapi-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / osaapi-1.0.1.tar.gz

Download URL osaapi-1.0.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
151ba9f09e1fbdc096758428538da23754e49e493112b2c02af3cbf77be9f247
BLAKE2b-256 checksum
How to use checksums
3199b15c5153b03d365d2b09b2dadb1b60d0c38bc5a8017519d308b29d997ee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.17 Linux/5.15.0-1041-azure

Release files / osaapi-1.0.1-py3-none-any.whl

Download URL osaapi-1.0.1-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
088b5db44b971ac6dca829b14cab5f2b9740225a6cd7cf4d1c2170be721a937f
BLAKE2b-256 checksum
How to use checksums
0ed83fbd993984bba3dacb700c2735dfdf26ee0f4942669de04ac3e20a0d4d49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.8.17 Linux/5.15.0-1041-azure

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.3.12

1 release file

0.3.11

1 release file

0.3.10

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page