Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
28636 Zobrazení

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
Zrušit

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,

Nejlepší odpověď

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
Zrušit
Autor

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 Odpovědi Zobrazení Aktivita
0
zář 24
899
0
kvě 24
26
1
dub 24
4164
0
bře 24
1253
0
bře 24
1356