تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
8 الردود
15707 أدوات العرض

I had heard somewhere that there were plans of implementing a RESTful API directly into Odoo, without the need for modules that translate between HTTP and XML-RPC. Unfortunately I cannot seem to remember where I heard this, perhaps it was something that came out of OpenDays? So:

  1. Is a RESTful API planned to be included into Odoo?
  2. If so, are there any estimates of when this feature might be included?
الصورة الرمزية
إهمال

Are you sure that this works? In my experience Odoo will raise an Exception if you try to return JSON-type responses from an HTTP-type URL (the type of the URL defaults to 'http'). If you've tested this and it works then that's great, though I am a little disappointed that we would have to roll our own REST API.

check my updated answer

أفضل إجابة

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.

الصورة الرمزية
إهمال
أفضل إجابة

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)


الصورة الرمزية
إهمال
الكاتب

Does this also correctly set response headers?

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

how can i contact you atte isoputo

أفضل إجابة

How do you do this ? help pls

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مارس 25
1252
0
يناير 25
3293
1
أغسطس 23
14589
change password تم الحل
1
أغسطس 23
13250
1
يوليو 23
10249