Skip to Content
Menu
This question has been flagged

I want to make a request to an external API when I create a record. It's possible to do that using python code in automated actions? or what's the best approach in order to get that? 

🖖

PD: I have zero experience in Odoo development. But I'm a developer ;)

Avatar
Discard

Hello Belmar,

To extend onto Husain's answer, regarding documentation, you want to look at building a module to install into Odoo.

https://www.odoo.com/documentation/14.0/howtos/backend.html

You will need to extend a model which would depend on where you want to call the API request. Specifically defined here in the documentation:

https://www.odoo.com/documentation/14.0/howtos/backend.html#model-inheritance

Once you have the function defined on the model, you are able to call this function in the automated action. Just choose python execution and you have selected the same model you have extended and write the code "record.your_function()".

I hope this explains how to achieve this better.

Thanks,

Best Answer

Hello Belmar

Yes you can call Extenal API with help of automated actions while you create record and also you can override create method to call your API.
You can call method for automated action like model.method_name()  
Make sure to handle response for both success and failure cases to avoid Errors.

Thanks

Avatar
Discard
Author

Thank you. Do you know any documentation that explains how to archive this?

You can see odoo documentation for building and inheriting module as Jack dane shared link.

If you are asking about to call API then you can use python requests module to call API.

Ex:

import json

import requests

headers = {"Content-Type": "application/json", "Accept": "application/json", "Catch-Control": "no-cache"}

url = "https://example.com"

json_data = {'name' : 'test'}

response = requests.post(url, data=json.dumps(json_data), headers=headers)

This is simple post request with json type.

Hope this will help you.

Related Posts Replies Views Activity
0
Sep 24
121
0
May 24
23
1
Apr 24
2621
0
Mar 24
419
0
Mar 24
541