Hello I need to make a request to an external platform using execute action, I have this code, but I don't know hot to make the request since I'm using Odoo 17 in SaaS mode and cannot import request library.
# Fetch API token and URL from system parameters
api_token = env["ir.config_parameter"].sudo().get_param("csp_api_token")
api_url = env["ir.config_parameter"].sudo().get_param("csp_api_url")
if not api_token:
log("Error: API token is missing", "error")
elif not api_url:
log("Error: API URL is missing", "error")
else:
log("API token obtained: " + api_token, "info")
log("API URL obtained: " + api_url, "info")
if record:
data = {
"id": record.id,
"sp_key": record.title if record.title else "Unknown",
"status": record.stage_id.name if record.stage_id else "Unknown",
# "lead_type": record.x_studio_tipo_de_oportunidad, # Uncomment when field is ready
"type": record.x_studio_project_type if record.x_studio_project_type else "Undefined",
"description": record.x_studio_field_hHzkr if record.x_studio_field_hHzkr else "No description",
"email": record.email_from if record.email_from else None,
"phone": record.phone if record.phone else None,
"currency": "USD",
"amount": record.expected_revenue if record.expected_revenue else 0,
"probability": record.probability if record.probability else 0,
"closing_date": record.date_deadline if record.date_deadline else None,
"customer": {
"id": record.partner_id.id if record.partner_id else None,
"name": record.partner_id.name if record.partner_id else "No Name",
"description": "Example description",
"email": record.partner_id.email if record.partner_id and record.partner_id.email else None,
"phone": record.partner_id.phone if record.partner_id and record.partner_id.phone else None
}
}
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + api_token
}
try:
response = env["ir.http"].sudo()._make_request(
url=api_url + "/sps",
data=data,
headers=headers,
method="POST"
)
# Log API Response
if response.get("status") and response["status"] >= 400:
log("API Request Failed: " + str(response), "error")
else:
log("API Request Successful: " + str(response), "info")
except Exception as e:
log("API Error: " + str(e), "error")
Someone can help me to figure it out how to do that the right way?