You could use something like this(this is an api test model that I create):
from openerp.osv import fields, osv
import requests
class solt_http_test(osv.osv):
_name = 'solt.http.test'
_columns = {
'name': fields.char('URL', size=1024),
'method': fields.selection([('post', 'POST'), ('get', 'GET'), ('put', 'PUT'), ('patch', 'PATCH'), ('delete', 'DELETE')], string='HTTP Method'),
'user': fields.char('User', size=64),
'password': fields.char('Password', size=64),
'content': fields.text('Content'),
'response': fields.text('Response'),
}
def action_request(self, cr, uid, ids, context=None):
for test in self.browse(cr, uid, ids,context):
auth = None
if test.user and test.password:
auth = (test.user,test.password)
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
result = getattr(requests, test.method)(test.name, test.content, auth=auth, headers=headers)
test.write({'response':result.text})
return True
solt_http_test()
Modify this for your convenience. Here is the views, action and menu i use:
<record id="solt_http_test_form_view" model="ir.ui.view">
<field name="name">solt.http.test.form</field>
<field name="model">solt.http.test</field>
<field name="arch" type="xml">
<form string="HTTP Test" version="7.0">
<header>
<button name="action_request" string="Test" type="object" icon="gtk-go-forward"/>
</header>
<sheet layout="auto">
<group colspan="6">
<field name="name"/>
<field name="method"/>
<field name="user"/>
<field name="password"/>
</group>
<group>
<field name="content"/>
</group>
<group>
<field name="response"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="solt_http_test_tree_view" model="ir.ui.view">
<field name="name">solt.http.test.model.tree</field>
<field name="model">solt.http.test</field>
<field name="arch" type="xml">
<tree string="HTTP Test" version="7.0">
<field name="name"/>
<field name="method"/>
</tree>
</field>
</record>
<record id="solt_http_test_action" model="ir.actions.act_window">
<field name="name">HTTP Tests</field>
<field name="res_model">solt.http.test</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="API Tests" id="solt_rest_weaver_menu" parent="base.menu_administration" sequence="5"/>
<menuitem name="HTTP Tests" id="solt_http_test_submenu" parent="solt_rest_weaver_menu" action="solt_http_test_action" sequence="2"/>
Hi, whether the application has REST api? Anyway, If you are getting a json object, you can use "loads()" of json library to convert it as a dictionary. Then you can extract the required data from that dictionary and do whatever you need using a python function.