Odoo Help

2
8 Answers
1
shashank verma
11/6/15, 3:40 AM

Hello Atte Isopuro,

We can use web controllers in Odoo to build REST API for synchronizing odoo with other application.

Agenda is to fetch partner(customer) ids

Steps as follows :

1. Create new file in controller directory and add your code-

###############this is for GET request##########################

class my_api_class(openerp.http.Controller):

@route("/get_partner/<name>/", auth='none')

def get_partner(self,name):

'''Get list of partners ids with matching name '''

if request.httprequest.method=='GET':

partner_obj = request.env['res.partner']

partner_ids_list=partner_obj.search(request.cr,1,[('name','=',name)])

return str(partner_ids_list)

return str('NOT A GET REQUEST')

##########################this is for POST request######################

@route("/insert_partner_data/", auth='none')

def create_partner(self,**vals):

''' create new partner '''

import ipdb;ipdb.set_trace()

partner_obj = request.env['res.partner']

###check if post request###

if request.httprequest.method=='POST' :

####get headers##########

header=request.httprequest.headers

partner_ids_list=partner_obj.create(request.cr,1,**vals)

return str(partner_ids_list)

2. Restart odoo server and hit below URL on browser

#########PYTHON SCRIPT TO CALL REST API#######

import request,json

##get request#####

url_for_get='http://localhost:8069/get_partner/odoopvtltd

resonse=request.get(url_for_get)

###POST request#####

url_post='http://localhost:8069/insert_partner_data'

data_to_post={'name':CNPltd,'email':'test@test.com'}

headers={'key':'value'}

response=requests.post(url_post,data_to_post,headers=headers)


3 Comments
Atte Isopuro
11/9/15, 2:21 AM

Does this also correctly set response headers?

shashank verma
2/29/16, 10:26 AM

Yes ... header=request.httprequest.headers Also check my update answer .I covered both GET and POST request

ojomo joseph
3/25/17, 7:22 AM

how can i contact you atte isoputo

0
dayle
5/22/18, 4:06 AM

How do you do this ? help pls

0
Shawn Anderson
9/9/16, 11:44 AM

So does this mean there is are no plans for RESTful APIs to be supported natively?  Is so that is a little disappointing to hear.

Ask a Question
Writer
Tags
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now