velaware Posted January 27, 2014 Report Posted January 27, 2014 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. Michael and ariq01 2 Quote
velaware Posted January 27, 2014 Author Report Posted January 27, 2014 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? Quote
Cody Posted January 27, 2014 Report Posted January 27, 2014 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. ariq01 1 Quote
velaware Posted January 27, 2014 Author Report Posted January 27, 2014 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. Working on a plugin to get all the known models that can be called via API thanks to knowing how loadModels works Quote
danmo Posted March 12, 2015 Report Posted March 12, 2015 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). Michael 1 Quote
mcrowson Posted July 10, 2015 Report Posted July 10, 2015 @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? Quote
danmo Posted July 13, 2015 Report Posted July 13, 2015 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) Quote
mcrowson Posted July 20, 2015 Report Posted July 20, 2015 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.