Hello, is there any way to cancel a document by backend from api request?

I’ve tried using frappe.get_doc().cancel() but it didn’t work.

je_doc = frappe.get_doc('Journal Entry', 'abc')
pr = frappe.get_doc('Purchase Receipt', {
'po_reference': data['params']['inbound_reference']})


I’ve done this before but still can’t answer my issue

Have you tried removing this line:


Also, are you getting any error messages in the logs? There might be documents related to the Purchase Receipt that are restricting the cancellation.

I dont use ignore_permissions=True before.

And in my case i think, this is securty/permission issues. because an API would known as Guest in ERPNext. and Guest can’t cancel a document.

or like you’ve said, maybe Purchase Receipt has restricted method to cancellation.

Also, i dont getting any error messages in the logs.

Thanks for answering. Appreciate that.

1 Like

Exactly as i thought.

when you receive a request from a webhook. and would like to change document either cancelling or deleting a document. ERPNext will assume that the request is “Guest” and with “Guest Role”.

You can change Guest Role in “Role List”. and allow DocType that you would like to cancel/delete.

1 Like

Giving anonymous users permission to cancel and delete is a huge security risk. In most circumstances, amuch better option will be to use some kind of authentication.


1 Like

You’re right, Thanks for your suggestion.
I will work for the authentication now.

1 Like

I am using the token based authentication to cancel submitted entry. There was nothing in the ERPNext doc to which API endpoint should I use to do it. I tried PUT /api/resource/:docType/:name with data = {‘docstatus’: 2} but got internal server error. Can you help me out in this?