Jump to content

Recommended Posts

Posted

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.

Posted
  On 1/27/2014 at 6:31 PM, Cody said:

Nice work!

Is there a doc or something I can reference for all the different methods I can call?  Or an API call that returns all the different models+methods?

Posted
  On 1/27/2014 at 6:36 PM, secforus_ehansen said:

Is there a doc or something I can reference for all the different methods I can call?  Or an API call that returns all the different models+methods?

 

Being that there are hundreds upon hundreds of possible requests, the best reference would be the source docs for all Models in addition to the API docs.

  • 1 year later...
Posted

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).
  • 3 months later...
Posted

@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?

Posted

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)
Posted

Praise the Lord that did it! I cannot tell you how often I've been scratching and banging my head on this one. Probably going to modify your flatten method to turn lists into those types of dicts

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...