Package: tryton-restful
A REST API for Tryton ModelsInstallationInstall from python package index:pip install tryton-restfulUsageOn installation you should be able to use thetryton_restfulscript which
runs a local development server.tryton_restful--helpUsage:tryton_restful[OPTIONS]HOSTPORTRunstheapplicationonalocaldevelopmentserver.Options:-c,--configTEXTPathtotrytonconfigurationfile--debug--threaded/--not-threadedshouldtheprocesshandleeachrequestinaseparatethread?--helpShowthismessageandexit.You can run the server by:tryton_restful -c /path/to/tryton/configTipYou can also specify the config file using environment variables.export TRYTON-CONFIG=/path/to/tryton/configRest API Endpoints:/<dbname>/loginPOSTExpectsloginandpasswordas form data and returns a JSON of
user ID and session to be used for subsequent requestsimportrequestsimportjsonDATABASE_NAME='rest'BASE_PATH='http://localhost:9000/'+DATABASE_NAMElogin_result=requests.post(BASE_PATH+'/login',data={'login':'admin','password':'admin'})tryton_session=login_result.json()printtryton_session{u'session': u'966689963c0a4a939cb326c1451b0fe9', u'id': 1}/<dbname>/model/<model.name>GETReturn a list of records (Just the ID and rec_name)Params:domain: JSON serialised domain expression
example:[[‘name’, ‘ilike’, ‘openlabs’]]page: Integer number of the pageper_page: The number of records to be returned per pageorder: JSON serialised order expression in which the records
should be sorted. Ex:[(‘name’, ‘ASC’), (‘date’, ‘DESC’)]s=requests.Session()s.auth=(tryton_session['id'],tryton_session['session'])# Use the session and get the list of usersprints.get(BASE_PATH+'/model/res.user').json(){u'items': [{u'rec_name': u'Administrator', u'id': 1}]}POSTCreates one or more records in the given model# Create a new userheaders={'content-type':'application/json'}values=[{'name':'Thomas','login':'thomas','password':'password'},{'name':'Alfred','login':'alfred','password':'somethingelse'},]users=s.post(BASE_PATH+'/model/res.user',data=json.dumps(values),headers=headers).json()printusers{u'items': [{u'rec_name': u'Thomas', u'id': 3}, {u'rec_name': u'Alfred', u'id': 4}]}DELETEDeleteallrecords in the given model/<dbname>/model/<model.name>/<id>GETReturn the details of the given recordParams:fields_names: specify the list of fields to be returned.
Default behavior is to return as much data as possible# Get full details of the first userprints.get(BASE_PATH+'/model/res.user/1').json(){u'create_date': u'Sat, 10 May 2014 08:51:16 GMT', ....}# Get only a limited set of fieldsuser_url=BASE_PATH+'/model/res.user/1'prints.get(user_url+'?fields_names=name&fields_names=email').json(){u'email': None, u'name': u'Administrator', u'id': 1}PUTUpdate the given resource# Change the email of the userheaders={'content-type':'application/json'}user_data=s.put(user_url,data=json.dumps({'email':'admin@example.com'}),headers=headers).json()printuser_data['email']admin@example.comDELETEDelete the given record# get a new list of all usersprints.get(BASE_PATH+'/model/res.user').json(){u'items': [{u'rec_name': u'Administrator', u'id': 1}, {u'rec_name': u'Thomas', u'id': 3}, {u'rec_name': u'Alfred', u'id': 4}]}# delete user Alfred with ID 4prints.delete(BASE_PATH+'/model/res.user/4')<Response [205]># get a new list of all usersprints.get(BASE_PATH+'/model/res.user').json(){u'items': [{u'rec_name': u'Administrator', u'id': 1}, {u'rec_name': u'Thomas', u'id': 3}]}