Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
2 changes: 1 addition & 1 deletion rest_api_odoo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"depends": ['base', 'web'],
"data": [
'security/ir.model.access.csv',
'views/res_users_views.xml',
'security/res_api_odoo_security.xml',
'views/connection_api_views.xml'
],
'images': ['static/description/banner.png'],
Expand Down
416 changes: 219 additions & 197 deletions rest_api_odoo/controllers/main.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion rest_api_odoo/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@
#############################################################################

from . import connection_api
from . import res_users
45 changes: 0 additions & 45 deletions rest_api_odoo/models/res_users.py

This file was deleted.

32 changes: 32 additions & 0 deletions rest_api_odoo/security/res_api_odoo_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">

<record model="ir.module.category" id="module_category_rest_api_odoo">
<field name="name">REST API</field>
<field name="description">Helps you manage your REST API records.</field>
<field name="sequence">17</field>
</record>

<record id="group_rest_api_odoo_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id"
ref="rest_api_odoo.module_category_rest_api_odoo" />
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]" />
</record>

<record id="base.default_user" model="res.users">
<field name="groups_id"
eval="[(4,ref('rest_api_odoo.group_rest_api_odoo_manager'))]" />
</record>

<record id="rest_api_odoo_rule_manager" model="ir.rule">
<field name="name">All REST APIs</field>
<field name="model_id" ref="model_connection_api" />
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups"
eval="[(4, ref('rest_api_odoo.group_rest_api_odoo_manager'))]" />
</record>

</data>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 44 additions & 76 deletions rest_api_odoo/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="col-sm-12 col-md-12 col-lg-12">
<!-- APP HERO -->
<h1 style="color: #FFFFFF; font-weight: bolder; font-size: 50px; text-align: center; margin-top: 50px;">
Odoo rest API</h1>
Odoo Rest API</h1>

<img src="./assets/screenshots/hero.gif" class="img-responsive"
width="100%" height="auto"/>
Expand Down Expand Up @@ -138,7 +138,7 @@ <h1 style="color: #FFFFFF; font-weight: bolder; font-size: 50px; text-align: cen
<div class="d-flex align-items-center"
style="margin-top: 30px; margin-bottom: 30px">
<img src="assets/misc/check-box.png" class="mr-2"/>
<span style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight: bold;">Authentication using the generated api key.</span>
<span style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight: bold;">Authentication using the generated API key.</span>
</div>
</div>
<div class="col-sm-12 col-md-6">
Expand Down Expand Up @@ -217,29 +217,21 @@ <h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight:
<li>First of all, we have to add a new parameter in odoo conf.
file.
</li>
<li><b>server_wide_modules = web, base, rest_api_odoo</b><br/>
<li><code>server_wide_modules = web, base, rest_api_odoo</code><br/>
- This will allow us to send request to server without
selecting database first.<br/>- Incase if you have to
uninstall the module , you have to remove this parameter.
<br/>- Next we can install the module.
</li>
<li>After installing the Rest api app we can see a new api key
<li>After installing the Rest API app we can see a new API key
field in users.
</li>
- Next we have to generate the api-key for the current
- Next we have to generate the API-key for the current
user.<br/>
<li>You can import the postman collections provided in the app
folder for authentication and interacting with database in
various methods.
</li>
</ul>
</p>
<img src="assets/screenshots/screenshot_1.png"
class="img-thumbnail">
<hr>
<center>
<img src="assets/screenshots/screenshot_9.png"
class="img-thumbnail"></center>
</div>

<div style="display: block; margin: 30px auto;">
Expand All @@ -248,45 +240,26 @@ <h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight:
</h3>
<p style="font-weight: 400; font-family: 'Montserrat', sans-serif; font-size: 14px;">
<ul>
<li>Next you have to select the database and login.</li>
<li>We have attached <b>Postman collections</b> through which
you can
authenticate rest api.
</li>
<li>First, extract the <b>zip</b> file. Then, you will obtain the JSON-format file, which you can directly import into <b>POSTMAN.</b></li>
<li>The url format will be like this - <b>http://cybrosys:8016/odoo_connect</b>
Replace 'cybrosys:8016' with your localhost port number.
</li>
<li>You have to provide database name, username and password
through the headers while sending request.
</li>
<li>If the authentication is successful , an api key will be
generated for the current user.
</li>
<li>This key will be used when sending api requests to
database.
</li>
<li>The response will be like this - <b> {"Status": "auth
successful", "User": "Mitchell Admin", "api-key":
"66c2ebab-d4dc-42f0-87d0-d1646e887569"}.</b></li>
<li>Next you have to generate the API key under <b>My Profile</b> > <b>Account Security</b>.</li>
<li>Set the name of the API key according to your needs.</li>
</ul>
</p>
<img src="assets/screenshots/screenshot_2.png"
class="img-thumbnail">
</div>
<div style="display: block; margin: 30px auto;">
<h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight: bold;">
Create records in Rest api app
Create records in Rest API app
</h3>
<p style="font-weight: 400; font-family: 'Montserrat', sans-serif; font-size: 14px;">
<ul>
<li>After rest api authentication, we can create records in the
rest api app.
<li>After creating the API key, we can create records in the
Rest API app.
</li>
<li>Here we can choose the model, and also we can
choose the http methods.
</li>
<li>The api response will be based on these records.</li>
<li>The API response will be based on these records.</li>
</ul>
</p>
<img src="assets/screenshots/screenshot_3.png"
Expand All @@ -307,26 +280,28 @@ <h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight:
</h3>
<p style="font-weight: 400; font-family: 'Montserrat', sans-serif; font-size: 14px;">
<ul>
<li>You can send GET request to retrieve data from the
<li>You can send <code>GET</code> request to retrieve data from the
database.
</li>
<li>The postman collection has been provided with app files for
sending request from postman.
</li>
<li>You have to provide username, password and api key through
the header.
<li>You have to provide the API key in the header: <code>Authorization: Bearer {API_KEY}</code>
where <code>{API_KEY}</code> should be replaced with the actual API key.</li>
</li>
<li>Model can be passed as argument as the technical name , and
also if you want
specific record you can provide the id as well.
<li>Model can be passed as argument as the technical name, and
also if you want to get a specific record you can provide any
of the related fields to the module as well.
</li>
<li>The format for GET method will be like this - <b>http://cybrosys:8016/send_request?model=res.partner&Id=10.</b>
<li>The format for GET method will be like this - <code>http://cybrosys:8016/send_request?model=res.partner&id=10.</code>
</li>
<li>We can specify the fields inside the JSON data, and it will
be like this - <b>{"fields": ["name", "email"]}.</b></li>
<li>This is the format of api response - <b>{"records": [{"id":
be like this - <code>{"fields": ["name", "email"]}</code>.
If no fields are passed , it will returns just the record's ID.
To get all of the fields, set the fields to wildcard - <code>{"fields": ["*"]}</code>.
Pagination can also be used by adding <code>{"limit": 10, "offset": 0}</code>
to the query parameter above.
</li>
<li>This is the format of API response - <code>{"records": [{"id":
10, "email": "deco.addict82@example.com", "name": "Deco
Addict"}]}.</b>
Addict"}]}</code>.
</li>

</ul>
Expand All @@ -338,31 +313,28 @@ <h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight:
</h3>
<p style="font-weight: 400; font-family: 'Montserrat', sans-serif; font-size: 14px;">
<ul>
<li>Using POST method , you can create new records in the
<li>Using <code>POST</code> method , you can create new records in the
database.
</li>
<li>Just make sure you enabled POST method for the model record
in rest api app , otherwise you will get <b>'method not
<li>Just make sure you enabled <code>POST</code> method for the model record
in Rest API app , otherwise you will get <b>'method not
allowed'</b> message.
</li>
<li>For creating record you have to provide the JSON data along
with the model.
</li>
<li>You can make use of the postman collection that we have
added with app files.
</li>
<li>The format for sending POST request will be like this - <b>http://cybrosys:8016/send_request?model=res.partner.</b>
<li>The format for sending POST request will be like this - <code>http://cybrosys:8016/send_request?model=res.partner.</code>
</li>
<li>This is the format for JSON data - <b>{
<li>This is the format for JSON data - <code>{
"fields" :["name", "phone"] ,
"values": {"name": "abc",
"phone":"55962441552"
} }.</b>
} }.</code>
</li>
<li>Make sure the data entered in correct format otherwise you
will get <b>'Invalid JSON data' message.</b></li>
<li>Response will be in this format - <b>{"New resource":
[{"id": 51, "name": "abc", "phone": "55962441552"}]}.</b>
<li>Response will be in this format - <code>{"New resource":
[{"id": 51, "name": "abc", "phone": "55962441552"}]}</code>.
</li>
</ul>
</p>
Expand All @@ -373,24 +345,20 @@ <h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight:
Update Records
</h3>
<ul>
<li>Updation of records in the database can be done with PUT
<li>Updation of records in the database can be done with <code>PUT</code>
method.
</li>
<li>You have to provide the model and also the id or the record
that you want to update.
</li>
<li>You can use the Postman collection that we have provided and , you
will be always have to send request with your login
credentials. Otherwise, it will be showing access denied.
</li>
<li>The format for sending PUT request will be like this - <b>http://cybrosys:8016/send_request?model=res.partner&Id=46.</b>
<li>The format for sending <code>PUT</code> request will be like this - <code>http://cybrosys:8016/send_request?model=res.partner&Id=46.</code>
</li>
<li>Here too you have to provide the JSON data through which the
updates will be done.
</li>
<li>The response format will be like this - <b>{"Updated
<li>The response format will be like this - <code>{"Updated
resource": [{"id": 46, "email": "abc@example.com", "name":
"Toni"}]}.</b></li>
"Toni"}]}</code>.</li>
</ul>
</p>

Expand All @@ -401,20 +369,20 @@ <h3 style="font-family: 'Montserrat', sans-serif; font-size: 18px; font-weight:
</h3>
<p style="font-weight: 400; font-family: 'Montserrat', sans-serif; font-size: 14px;">
<ul>
<li>Database records can be deleted by sending DELETE method
<li>Database records can be deleted by sending <code>DELETE</code> method
request.
</li>
<li>For the deletion we have to provide the Model and the record
id that we want to delete.
</li>
<li>Make sure you have permission to delete files for the
selected model in the rest api record.
selected model in the Rest API record.
</li>
<li>The delete request format will be like this - <b>http://cybrosys:8016/send_request?model=res.partner&Id=46.</b>
<li>The delete request format will be like this - <code>http://cybrosys:8016/send_request?model=res.partner&Id=46.</code>
</li>
<li> The response after successful deletion will be -<b>
<li> The response after successful deletion will be -<code>
{"Resource deleted": [{"id": 46, "email": "abc@example.com",
"name": "Toni"}]}.</b></li>
"name": "Toni"}]}</code>.</li>
</ul>
</p>

Expand Down Expand Up @@ -843,7 +811,7 @@ <h4>Need Help?</h4>
<div>
<h4>WhatsApp</h4>
<p style="line-height: 100%;">Say hi to us on WhatsApp!</p>
<a href="https://api.whatsapp.com/send?phone=918606827707">
<a href="https://API.whatsapp.com/send?phone=918606827707">
<p style="font-weight: 400; font-size: 28px; line-height: 80%; color: #714B67;">
+91 86068
27707</p>
Expand Down
18 changes: 0 additions & 18 deletions rest_api_odoo/views/res_users_views.xml

This file was deleted.