Lead can't be found, still he exist

Hey guys, I want to implement a function which i can send a mail to a lead by choosing out of the email template. All the things i want are working but it seems to fail at the last instance.
this is the error i get when i want to send it: Lead [“CRM-LEAD-2024-00025”] not found

it says that the Lead with that ID isnt found, but this lead exists, and the URL of the Lead is also correct. I think the mistake is by handing over the lead_id but Im not completely sure.

This is my javascript and python code.

lead_list.js

function send_email_to_leads(lead_id, template) {
frappe.call({

  method: "erpnext.crm.doctype.lead.send_email_to_leads.send_email_to_leads",
  args: {
	lead_id: lead_id,
	template: template
  },
  callback: function(response) {
	if (response.message) {
	  frappe.show_alert(__("E-Mail erfolgreich gesendet"));
	} else {
	  frappe.show_alert(__("Fehler beim Senden der E-Mail"));
	}
  }
});

}

send_email_to_leads.py

import frappe

@frappe.whitelist()
def send_email_to_leads(lead_id, template):

lead = frappe.get_doc("Lead", lead_id)
email_template = frappe.get_doc("Email Template", template)
email_content = frappe.render_template(email_template.message, {"doc": lead})
 

frappe.sendmail(
    recipients=lead.email_id,
    sender=frappe.session.user,
    subject=email_template.subject,
    content=email_content
)

return True

Hi @krixi,

You can add some debug prints to your Python function to see if the lead_id is correctly received and if it’s able to fetch the Lead document.

For example:

import frappe

@frappe.whitelist()
def send_email_to_leads(lead_id, template):
    print("Received lead_id:", lead_id)
    lead = frappe.get_doc("Lead", lead_id)
    print("Retrieved lead:", lead)

Check the output, and lead name getting correct or wrong.

Thank You!

Thanks for your quick response, i added the prints, but they dont show up in the browser console. so i dont even get in there as it seems.

I get that error message in my console debugger
POST
https://erp.mytest.here/api/method/erpnext.crm.doctype.lead.send_email_to_leads.send_email_to_leads
[HTTP/1.1 404 NOT FOUND 52ms]

so it cant resolve the url but i dont know what to change

Hi @krixi,

Please check the references of the frappe.call

I hope this helps.

Thank You!