Search 1.9 billion lines of Odoo code on GitHub

restful

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&#39;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 = { &#39;content-type&#39;: &#39;application/x-www-form-urlencoded&#39;, &#39;charset&#39;:&#39;utf-8&#39; }</p> <p>data = { &#39;login&#39;: &#39;admin&#39;, &#39;password&#39;: &#39;admin&#39;, &#39;db&#39;: &#39;demo<em>db&#39; } base</em>url = &#39;http://theninnercicle.com.ng&#39;</p> <p>req = requests.get(&#39;{}/api/auth/token&#39;.format(base_url), data=data, headers=headers)</p> <p>content = json.loads(req.content.decode(&#39;utf-8&#39;))</p> <p>headers[&#39;access-token&#39;] = content.get(&#39;access_token&#39;) # add the access token to the header print(headers) ```</p> <h3>To delete acccess-token</h3> <p><code>python req = requests.delete(&#39;%s/api/auth/token&#39;%base_url, data=data, headers=headers) </code></p> <h3>[GET]</h3> <p>```python req = requests.get(&#39;{}/api/sale.order/&#39;.format(base_url), headers=headers, data={&#39;limit&#39;: 10, &#39;domain&#39;: []})</p> <h1><em>**Pass optional parameter like this *</em>*</h1> <p>{ &#39;limit&#39;: 10, &#39;domain&#39;: &quot;[(&#39;supplier&#39;,&#39;=&#39;,True),(&#39;parent_id&#39;,&#39;=&#39;, False)]&quot;, &#39;order&#39;: &#39;name asc&#39;, &#39;offset&#39;: 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(&#39;%s/api/res.partner/&#39;%base_url, headers=headers, data=json.dumps({ &#39;name&#39;:&#39;John&#39;, &#39;country_id&#39;: 105, &#39;child_ids&#39;: [{&#39;name&#39;: &#39;Contact&#39;, &#39;type&#39;:&#39;contact&#39;}, {&#39;name&#39;: &#39;Invoice&#39;, &#39;type&#39;:&#39;invoice&#39;}], &#39;category_id&#39;: [{&#39;id&#39;:9}, {&#39;id&#39;: 10}] } )) print(p.content) </code></p> <p><strong>PUT Request</strong> <code>python p = requests.put(&#39;http://theninnercicle.com.ng/api/res.partner/68&#39;, headers=headers, data=json.dumps({ &#39;name&#39;:&#39;John Doe&#39;, &#39;country_id&#39;: 107, &#39;category_id&#39;: [{&#39;id&#39;: 10}] } )) print(p.content) </code></p> <p><strong>DELETE Request</strong> <code>python p = requests.delete(&#39;http://theninnercicle.com.ng/api/res.partner/68&#39;, headers=headers) print(p.content) </code> req = requests.get(&#39;{}/api/sale.order/&#39;.format(base_url), headers=headers,data={&#39;limit&#39;: 10, &#39;domain&#39;: []})</p>