# respond to API
if frappe.form_dict.message == "ping":
frappe.response['message'] = "pong"
else:
frappe.response['message'] = "ok"
It works. Tested using postman.
“Allow Guest” is ticked.
With “Allow Guest” unticked it does not work. Good.
Then I used the token of a website user in postman and the script works. Which is not good for this script.
Is there some code that can be placed above the test code so that it will check the role of the authentication and only allow if it is “System Manager”?
# Restrict to System Manager only
session_user = frappe.session.user
user_roles = frappe.get_roles(session_user)
# Allow only System Manager roles.
if "System Manager" not in user_roles:
frappe.throw("Access Denied: Only System Managers can access this API", frappe.PermissionError)
Postman is giving the following error.
"exception": "AttributeError: module has no attribute 'get_roles'",
The way I understand it - this example is just to ping the server and see if it is responding
Create two users - one with access to customer list and one without. Get their API key and secret and then put in postman
When you make a GET request for the customer list the first one will be allowed and the second will be denied. The permission check kicks in and each api key is allowed based on their authorizations