Author: |
Babatope Ajepe |
License: |
LGPL-3 |
Branch: |
12.0 |
Repository: |
elmosolutions/odoo-addons |
Dependencies: |
base,
and
web |
Languages: |
HTML (14, 2.6%),
Markdown (70, 12.8%),
Python (412, 75.5%),
and
XML (50, 9.2%) |
Other branches: |
10.0,
11.0,
and
master |
Other repositories: |
Bedo1212/odoo-addons,
Coding-Squad/odoo-addons,
Jaquedeveloper/odoo-addons,
Rodasac/odoo-addons,
ajepe/odoo-addons,
akurey/ajepe-odoo-addons,
cialuo/odoo-addons-3,
cnkenny/odoo-addons,
consultingerp/odoo_redis_session_storage,
haylahi/odoo-addons-6,
latera/odoo-restful,
leodoooca/odoo-addons,
niulinlnc/odoo-addons-1,
scbrianti/odoo-addons-2,
sspankaj/odoo-addons,
thinkwelltwd/odoo-addons,
wahello/ajepe-odoo-addons,
wahhid/odoo-addons,
wbsouza/odoo-addons-1,
and
wuhuizhong/odoo-addons |
<h3>Odoo RESTful API(restful)</h3>
<p>This is an HTTP framework that only cares about generating an HTTP response for each HTTP
request.
In other to use this module, a basic understating of Odoo RPC interface is required(though not that neccessary) especially when dealing with Many2many and One2many relationship. The implementation sits on the existing Odoo RPC features, data structures and format when creating or delecting Odoo's records are still applicable. I will be demostrating the usage using python request library.</p>
<h4>Access token request</h4>
<p>An access token is required in other to be able to perform any operations and ths token once generated should alway be send a long side any subsequents request.
```python
import requests, json</p>
<p>headers = {
'content-type': 'application/x-www-form-urlencoded',
'charset':'utf-8'
}</p>
<p>data = {
'login': 'admin',
'password': 'admin',
'db': 'demo<em>db'
}
base</em>url = 'http://theninnercicle.com.ng'</p>
<p>req = requests.get('{}/api/auth/token'.format(base_url), data=data, headers=headers)</p>
<p>content = json.loads(req.content.decode('utf-8'))</p>
<p>headers['access-token'] = content.get('access_token') # add the access token to the header
print(headers)
```</p>
<h3>To delete acccess-token</h3>
<p><code>python
req = requests.delete('%s/api/auth/token'%base_url, data=data, headers=headers)
</code></p>
<h3>[GET]</h3>
<p>```python
req = requests.get('{}/api/sale.order/'.format(base_url), headers=headers,
data={'limit': 10, 'domain': []})</p>
<h1><em>**Pass optional parameter like this *</em>*</h1>
<p>{
'limit': 10, 'domain': "[('supplier','=',True),('parent_id','=', False)]",
'order': 'name asc', 'offset': 10
}</p>
<p>print(req.content)</p>
<p>```</p>
<h3>[POST]</h3>
<p>```python</p>
<p><strong>POST request</strong>
<code>python
p = requests.post('%s/api/res.partner/'%base_url, headers=headers,
data=json.dumps({
'name':'John',
'country_id': 105,
'child_ids': [{'name': 'Contact', 'type':'contact'},
{'name': 'Invoice', 'type':'invoice'}],
'category_id': [{'id':9}, {'id': 10}]
}
))
print(p.content)
</code></p>
<p><strong>PUT Request</strong>
<code>python
p = requests.put('http://theninnercicle.com.ng/api/res.partner/68', headers=headers,
data=json.dumps({
'name':'John Doe',
'country_id': 107,
'category_id': [{'id': 10}]
}
))
print(p.content)
</code></p>
<p><strong>DELETE Request</strong>
<code>python
p = requests.delete('http://theninnercicle.com.ng/api/res.partner/68', headers=headers)
print(p.content)
</code>
req = requests.get('{}/api/sale.order/'.format(base_url), headers=headers,data={'limit': 10, 'domain': []})</p>