Skip to Content
Menu
This question has been flagged
2 Replies
2506 Rodiniai

Hi, I want to create a button on the Lead/Opportunity model that I will link to a server action (Nicholas Kosinski has a tutorial on this).


My requirement is that I want to make a POST request to a remote Angular server (I have a specific URL for that) when this button is clicked. Part of that URL will be some information of the opportunity record (e.g. name, address).


Can I do this using a few lines of python code inside a server action? Please share an example. Thank you!

Portretas
Atmesti
Best Answer

Hi Tushar, you can try this code:



lead_name = record.name or ''
customer_name = record.partner_id.name if record.partner_id else ''
email = record.email_from or ''
phone = record.phone or ''
payload = {
    'nombre': lead_name,
    'cliente': customer_name,
    'correo_electronico': email,
    'telefono': phone,
}
url = 'https://notify.run/testpost'
requests.post(url, json=payload)


I have not a v13 instance to test, but it's working on v17.

Best regards





Portretas
Atmesti
Best Answer

You can call any HTTP action (GET, POST, PUT ... ) within your Python code, as long as you define what launches this action, and send as parameters the information you want to send to another server.
This can also be done to retrieve information, like from APIs, web services, etc.

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
geg. 22
3090
0
vas. 22
157
1
rugs. 20
5204
2
spal. 24
3778
0
rugs. 24
651