Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

API Integration example

Subscribe

Get notified when there's activity on this post

This question has been flagged
apiexample
20 Replies
57306 Views
Avatar
Yves Goldberg

I am looking for example on how to integrate an external application that provides an API.

i.e. I get a json object from that external application after a request in the form of:

GET ONE: curl -u username:password http://server.com:2222/api/user/1234

Is there a module that show how I would use that collected data and use it in Odoo?


TIA

1
Avatar
Discard
Akhil P Sivan

Hi, whether the application has REST api? Anyway, If you are getting a json object, you can use "loads()" of json library to convert it as a dictionary. Then you can extract the required data from that dictionary and do whatever you need using a python function.

Avatar
Axel Mendoza
Best Answer

You could use something like this(this is an api test model that I create):

from openerp.osv import fields, osv
import requests

class solt_http_test(osv.osv): _name = 'solt.http.test' _columns = { 'name': fields.char('URL', size=1024), 'method': fields.selection([('post', 'POST'), ('get', 'GET'), ('put', 'PUT'), ('patch', 'PATCH'), ('delete', 'DELETE')], string='HTTP Method'), 'user': fields.char('User', size=64), 'password': fields.char('Password', size=64), 'content': fields.text('Content'), 'response': fields.text('Response'), } def action_request(self, cr, uid, ids, context=None): for test in self.browse(cr, uid, ids,context): auth = None if test.user and test.password: auth = (test.user,test.password) headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} result = getattr(requests, test.method)(test.name, test.content, auth=auth, headers=headers) test.write({'response':result.text}) return True solt_http_test()

Modify this for your convenience. Here is the views, action and menu i use:

        <record id="solt_http_test_form_view" model="ir.ui.view">
<field name="name">solt.http.test.form</field>
<field name="model">solt.http.test</field>
<field name="arch" type="xml">
<form string="HTTP Test" version="7.0">
<header>
<button name="action_request" string="Test" type="object" icon="gtk-go-forward"/>
</header>
<sheet layout="auto">
<group colspan="6">
<field name="name"/>
<field name="method"/>
<field name="user"/>
<field name="password"/>
</group>
<group>
<field name="content"/>
</group>
<group>
<field name="response"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="solt_http_test_tree_view" model="ir.ui.view">
<field name="name">solt.http.test.model.tree</field>
<field name="model">solt.http.test</field>
<field name="arch" type="xml">
<tree string="HTTP Test" version="7.0">
<field name="name"/>
<field name="method"/>
</tree>
</field>
</record>
<record id="solt_http_test_action" model="ir.actions.act_window">
<field name="name">HTTP Tests</field>
<field name="res_model">solt.http.test</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="API Tests" id="solt_rest_weaver_menu" parent="base.menu_administration" sequence="5"/> 
<menuitem name="HTTP Tests" id="solt_http_test_submenu" parent="solt_rest_weaver_menu" action="solt_http_test_action" sequence="2"/>



3
Avatar
Discard
ABU K

Hi All, What information I can pass in this fields ,I mean URL HTTP Method User Password Content Response 'name': fields.char('URL', size=1024), 'method': fields.selection([('post', 'POST'), ('get', 'GET'), ('put', 'PUT'), ('patch', 'PATCH'), ('delete', 'DELETE')], string='HTTP Method'), 'user': fields.char('User', size=64), 'password': fields.char('Password', size=64), 'content': fields.text('Content'), 'response': fields.text('Response'),

ABU K

Can you explain with an example?

Axel Mendoza

Just install it packaged in a module and use it throw the view, for example with url like http://google.com, and method get

ABU K

I got this Error result = getattr(requests, test.method)(test.name, test.content, auth=auth, headers=headers) TypeError: get() takes exactly 1 argument (4 given)

ABU K

When I try using GET Method ...

ABU K

I try with google.com, and method is GET ,but i got above error also here what is the username=? and password=? Need a help...........Axel

Axel Mendoza

The error of get that takes 1arg and received 4 is related to the version that you are using of requests. You need to adjust to the http methods signature of your requests version. The username and password refers to http basic auth

Avatar
Shinu
Best Answer

If you need any support in Odoo Integration, please refer https://www.confianzit.com/odoo-integration

0
Avatar
Discard
Avatar
stanislav ploschansky
Best Answer

Alex,  thank you for posting this. I'm a newbie in Odoo and need to integrate auto action to our system (asap as usually:) 
I'm stucked currently with initial step:
    import requests
It gives me following error:
   Odoo Server Error - Validation Error: forbidden opcode(s) in 'import Requests': IMPORT_NAME.

Could someone give me a hint how to enable using "requests"?

0
Avatar
Discard
Axel Mendoza

requests is this library at: http://docs.python-requests.org

you need to install it first,

pip install requests

should works

stanislav ploschansky

Thank you for answer! But ... is that possible to do for free edition of Odoo? Is there some kind of sandbox to install external modules?

Axel Mendoza

Yes, of course, Odoo is Open Core so as long as you know what you do you could do anything

stanislav ploschansky

that's cool! But i'm using Odoo like https://my.odoo.com, so where is console to install module? Or should I use Install Model from UI menu (which expect ZIP file) and prepare it first from docs.python-requests.org?

Axel Mendoza

No way then to do it, since you don't have the permissions to do the required installs and customizations

stanislav ploschansky

arg... bad news. Could you recommend some else way to have automated actions for integration purpose? I need to setup some trigger on changes in Odoo and hit another system then. Or only the way is have own installation of Odoo?

Axel Mendoza

Your issue doesn't seems to be with requests, since that library is included as a python dependency in requirements.txt

The issue seems to be in the place where your code is located or the way it's loaded. Maybe it's because you are importing the module or something. Maybe you need to install on promise or on own your cloud server vps

stanislav ploschansky

OK, thank you once again! I'll try find a way to continue.

Avatar
Yves Goldberg
Author Best Answer

Thank you Axel

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How do I get Product Prices with json API? Solved
api
Avatar
Avatar
1
Nov 25
2747
Has anyone integrated Helpdesk with Zoom for meeting scheduling?
api
Avatar
Avatar
1
Aug 25
1350
Using API check if Odoo is using Odoo sh or on-premises hosting. Solved
api
Avatar
Avatar
1
Aug 25
1724
External API XMLRPC Authentication Keeps Replying with false
api
Avatar
Avatar
Avatar
2
Jul 25
4648
API xmlrpc - upload pdf bills to account Solved
api
Avatar
Avatar
Avatar
3
Jul 25
1810
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now