Jump to content

Blesta Api Python Version


velaware

Recommended Posts

Blesta's work is heavily based on PHP.  However, Python is my go-to language of choice.  So, I decided to take Blesta's publicly available API SDK and convert it to Python using standard Python libraries (so no special pip commands needed!).

 

Here's the link: https://github.com/anzenehansen/Blesta-Goodies/tree/master/api

 

Right now it works just the same as the PHP version (I basically mirrored it to Python) but soon I plan on making it more Pythonic (hate that word but best way to describe it).  I love ORM style solutions so that is one of the first things I'm going to turn it into.

 

Its by default 755 if you git it, that was simply due to testing.

Link to comment
Share on other sites

  • 1 year later...

Nice work! Just to anyone looking to implement this, it looks like it needs the associated Blesta plugin installed to work.

 

Of course I discovered your work too late, after developing my own wrapper for python. It's pretty basic but also quite battle tested. You can feed in array args as a standard python dictionary and it outputs to the API in a format Blesta likes,

 

e.g.

{"vars": {"type": "cc", "account_id": "48"}, "client_id": 1}
becomes
[('vars[type]', 'cc'), ('client_id', 1), ('vars[account_id]', u'48')]
It does have one external dependency though (the wonderful requests module).
Link to comment
Share on other sites

  • 3 months later...

@danmo, I've been using your python plugin, thanks so much for making it. I have been having an issue though with nested lists within dictionaries and was hoping you could help.

 

My aim is to create an invoice from a service. I tried using the method createFromServices, but I always get an error saying that there is not a description for the service. I also tried creating the invoice separately and then adding the service to the invoice but with the same effect. When I create the invoice and add line items to it, including the service, it does not give me any errors, but none of the line items are added. Have you had any success linking services to invoices with your library?

Link to comment
Share on other sites

Hmm, I don't have any experience working with services, that's an aspect of Blesta I don't use.

 

I have no issues creating an invoice and adding line items though. The problem could be that you're nesting lists in the dictionary. The API wrapper expects you to nest dictionaries within dictionaries, for example:

value_dict = {'vars': {
    'client_id': 12,
    'date_billed': '2015-07-13 06:24:27 UTC',
    'date_due': '2015-07-13 06:24:27 UTC',
    'status': 'active',
    'currency': 'AUD',  # ISO 4217 3-character currency code
    'lines': {
        '0': {
            'description': 'Test line item',
            'qty': '1',
            'amount': '12',
            'tax': 'true'
        }},
}}

r = blesta.api().call(verb='post', classname='invoices', method='add', value_dict=value_dict)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...