magento.api
Generic API for magento
copyright: |
|
---|---|
copyright: |
|
license: | AGPLv3, see LICENSE for more details |
Generic API to connect to magento
This is the Base API class which other APIs have to subclass. By default the inherited classes also get the properties of this class which will allow the use of the API with the with statement
A typical example to extend the API for your subclass is given below:
from magento.api import API
class Core(API):
__slots__ = ( )
def websites(self):
return self.call('ol_websites.list', [])
def stores(self):
return self.call('ol_groups.list', [])
def store_views(self):
return self.call('ol_storeviews.list', [])
The above real life example extends the API for the custom API implementation for the magento extension
magento-community/Openlabs_OpenERPConnector
Example usage
from magento.api import API
with API(url, username, password) as magento_api:
return magento_api.call('customer.list', [])
Note
Python with statement has to be imported from __future__ in older versions of python. from __futur__ import with_statement
If you want to use the API as a normal class, then you have to manually end the session. A typical example is below:
from magento.api import API
api = API(url, username, password)
api.connect()
try:
return api.call('customer.list', [])
finally:
api.client.endSession(api.session)
Parameters: |
|
---|
Connects to the service but does not login. This could be used as a connection test
Entry point for with statement Logs in and creates a session
Exit point
Closes session with magento
Proxy for SOAP call API
Proxy for multicalls