Can't insert new doc with guest API call

This is my code:

@frappe.whitelist(allow_guest=True)
def create_daily_trip_logs():
	try:
		students = frappe.db.get_all('Students', filters={'status':'Active'},fields=['name','full_name'])
		for stds in students:
			doc = frappe.get_doc({
				'doctype':'Trip Logs',
				'student_id': stds.name,
				'trip_type': 'HTS'
			})
			doc.insert(ignore_permissions=True)
			doc2 = frappe.get_doc({
				'doctype':'Trip Logs',
				'student_id': stds.name,
				'trip_type': 'STH'
			})
			doc2.insert(ignore_permissions=True)
		frappe.response["message"] ={
					'status_key':1,
					'message': 'Daily Trip Logs created successfully'
				}
	except Exception as e:
		frappe.response["message"] = {
				'status_key':0,
				'error': e,
				'message':"something went wrong",
			}

Whenever I call this script using 3rd party scheduler system (Cron Job) no ‘Trip logs’ Documents got created. I already gave permessions to Guest to create this document.

if there any thing missing in my code let me now please. Thank you all

Hi @seif_khelifi,

I haven’t idea but

To debug the issue, you can add some debugging statements to log the exception details to better understand what might be going wrong.

For example:

except Exception as e:
    frappe.log_error(str(e))  # Log the error for debugging
    frappe.response["message"] = {
        'status_key': 0,
        'error': str(e),
        'message': "something went wrong",
    }

and also verify the permissions, field names.

I hope this helps.

Thank You!

2 Likes