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

I need to push the data to another application by calling a web service through Odoo. The other application developers are provided the web API in JSON format. I need to push the data to that application through that web services from Odoo.

I don't know how to do it. If anyone is known I request to explain with an example.

Thanks in advance.


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

Hello, This is an exemple for Odoo 11. Hope it help you

1. You need to fix the database in your odoo conf file

[options]

; This is the password that allows database operations:

; admin_passwd = admin

db_name = your_database_name

dbfilter = your_database_name

list_db = False

2. Then you can try this sample code

# -*- coding: utf-8 -*-
import json
from odoo import http
from odoo.http import request, Response

class MyApiClass(http.Controller):

@http.route("/my/get/api/path", auth='none', type='http', method=['GET'], cors='*')
def get_api_method(self, *kw):
partners = request['res.partners'].sudo().search_read([])

headers = {'Content-Type': 'application/json'}
body = { 'results': { 'code': 200, 'message': partners } }

return Response(json.dumps(body), headers=headers)


@http.route("/my/post/api/path", auth='none', type='http', method=['POST'], csrf=False, cors='*')
def post_api_method(self, email, *kw):
partners = request['res.partners'].sudo().search_read([('email','=',email)])

headers = {'Content-Type': 'application/json'}
body = { 'results': { 'code': 200, 'message': partners } }

return Response(json.dumps(body), headers=headers)
الصورة الرمزية
إهمال
الكاتب

The problem is, they provided an url and authentication token too. Where should I use those things in Odoo ?

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 24
11908
5
سبتمبر 20
6242
1
ديسمبر 19
9663
4
يناير 19
9283
1
يناير 19
6290