Package: em7api
An unofficial Python wrapper for the Science Logic EM7 APIGitHub:https://github.com/dougip/em7api/PyPI:https://pypi.org/project/em7api/Getting StartedInstallationInstall from the PyPI repositorypipinstallem7apiPrerequisitesThe following are required:URI of an existing EM7 portalusernamepasswordConfiguration fileCreate a file named .em7api located in one of these locations:Home directory: ~/.em7apiPresent working directory: ./.em7apiFile format:[DEFAULT]uri=https://em7.example.comusername=myEM7userpassword=myEM7passwordMore than one environment can be configured by adding additional sections:[DEFAULT]uri=https://em7.example.comusername=myEM7userpassword=myEM7password[PRODUCTION]uri=https://prod.em7.example.comusername=prodEM7userpassword=prodEM7user[DEV]uri=https://dev.em7.example.comUsagePassing credentials to the constructorThe non-default environments can be chosen by passing the environment parameter to the constructor:importem7apidev_session=em7api.EM7API(environment='DEV',verify_ssl=False)The credentials and URI can also be passed as parameters instead of configured in a file:importem7apisession=em7api.EM7API(uri='https://em7.example.com',\username='myEM7user',\password='myEM7pass',\verify_ssl=False)verify_ssl optionIf SSL verification fails, the API call will fail with an SSL error.  The easiest way to deal with this is to disable ssl by setting verify_ssl to False when calling the constructor.  The verify_ssl value just gets passed to requests’s verify value and can be either True, False, or the location of a CA_bundle.  This is not disabled by default due to the obvious security implications.importem7apidev_session=em7api.EM7API(verify_ssl=False)getRead operations are done with a get.  Doing a get with the URI of a resource will usually return a list of the related objectsprintsession.get('/api/account')Each object will have its own URI, and doing a get on that will return details of that specific objectprintsession.get('/api/account/1')limit parameterBy default, EM7 limits its search to 100.  If the data set is greater than that, the limit parameter needs to be specifiedprintsession.get('/api/powerpack',parameters={'limit':200})FiltersThe filter parameter can be sent to filter the results.  The available filters can be found in the API browser or in the API manualprintsession.get('/api/powerpack',parameters={'limit':1000,\'filter.0.name.begins_with':'Science'})More than one filter can be added.  Each additional filter needs its number incremented.printsession.get('/api/powerpack',parameters={'limit':1000,\'filter.0.name.begins_with':'Science',\'filter.1.name.contains':'EM7'})postAdding and updating objects is done with a post.  The data dictionary contains the details that need to be set for the new or updated object.  Whatever is not specified in the data dictionary will mostly be left alone or set to a default value.  The following would add a new organization, specifying the company name and leaving the rest blank:session.post('/api/organization',data={'company':'My Company'})To update an existing object, specify its own URI as the resource, and pass the changes in the data dictionarysession.post('/api/organization/1',data={'company':'Your Company'})putUpdates can also be done with a put.  This is more restrictive, as it requires the object to already exist and requires a larger set of the objects’ details to be sent in the data dictionary, otherwise it will result in an error.session.put('/api/organization/1',data={'company':'Another Company',\'address':'',\'city':'New York',\'state':'NY',\'zip':'',\'country':'US',\'contact_fname':'',\'contact_lname':'',\'title':'',\'dept':'',\'billing_id':'',\'crm_id':'',\'phone':'',\'fax':'',\'tollfree':'',\'email':'',\'date_create':None,\'date_edit':'',\'updated_by':'/api/account/1',\'theme':'1',\'longitude':'',\'latitude':'',\'notification_append':None})deleteObjects can be removed with a delete.session.delete('/api/organization/1')AcknowledgmentsThis project relies on the requests module to make the API callsLicenseThis project is licensed under theMIT license