Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
18795 มุมมอง

Hi,

I'm fairly new to odoo and am exploring odoo's features. I'm even newer to API's, just started learning on them.

As i was searching for how to connect to api's using odoo, the results weren't much satisfactory and the documentation was also so-so for a newbie like me, so i'm expecting odoo experts on here to help me out.

I have a simple api ( https://reqres.in/api/users/2 ) which returns some sample data when called, Now how do i connect or call it in python and display the returned values in xml?

Thanks in advance

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can use the python's requests library for fetching data. To display values in XML, you have to make columns in the table compatible for storing your data returned from the link. If you need to display with website templates then no need of columns in DB, but you have to write the template. Goto Odoo's Documentation is well documented and some external things, you have to find from the correct sources.

eg:

def get_ip_address(self):
r = requests.post("http://ifconfig.me")
data = r.json()
return data

In this example, I am getting the IP address of PC using the API and it returns some data as text. You have to process the return data according to your API documentation.

อวตาร
ละทิ้ง
ผู้เขียน

Thank you, the link cleared a few doubts for me. Tried out an example referring to the link and it works :)

คำตอบที่ดีที่สุด

Hi,

Read about requests library https://2.python-requests.org//en/v0.10.6/api/

it will help you how to send request and get a response.  https://www.geeksforgeeks.org/get-post-requests-using-python/

this will help you understand about api.

Regards,

Silvestar

อวตาร
ละทิ้ง
ผู้เขียน

Thank you for the links Silverstar, can you also post a sample code on how to call the above api and how to access the results?

This is the correct answer, he has given you the correct documentation.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 20
7769
1
ส.ค. 25
488
2
ก.ค. 25
2928
API xmlrpc - upload pdf bills to account แก้ไขแล้ว
3
ก.ค. 25
690
1
มิ.ย. 25
2175