Integration with N8N / Script Running On Local Machine

Good afternoon, I am trying to send some simple data from my pc to my erpnext instance but I kept getting the error below:

{“exception”:“frappe.exceptions.PermissionError”,“exc_type”:“PermissionError”,“exc”:“[“Traceback (most recent call last):\n File "apps/frappe/frappe/app.py", line 110, in application\n response = frappe.api.handle(request)\n File "apps/frappe/frappe/api/init .py", line 49, in handle\n data = endpoint(**arguments)\n File "apps/frappe/frappe/api/v1.py", line 76, in read_doc\n raise frappe.PermissionError\nfrappe.exceptions.PermissionError\n”]”,“_server_messages”:“["{"message": "User Guest does not have doctype access via role permission for document

The issue I am running into is that I am creating the API Credentials on my “Admin” account which has full access to every document.

I have tried to connect to N8N as well but encountered this error:
" Couldn’t connect with these settings

Retry

FORBIDDEN"

Appreciate any help, thank you.

Hi @mohamed13 ,

Can you share the API Details like payload endpoint etc to better understand the issue.

Thanks for your response, below is my python script and the error message I am encountering:

import requests
import json


ERP_URL = "https://[my_domain].com"  #URL
API_KEY = "***************"  #API Key
API_SECRET = "***************"  #API Secret


HEADERS = {
    "Authorization": f"token {API_KEY}:{API_SECRET}",
    "Content-Type": "application/json"
}


employee_data = {
    "doctype": "Employee",
    "first_name": "Test",
    "employee_number": "177",
    "date_of_birth": "01-01-1990",
    "gender": "Male",
    "date_of_joining": "01-01-2025"
}


endpoint = f"{ERP_URL}/api/resource/Employee"


try:
    response = requests.post(endpoint, headers=HEADERS, data=json.dumps(employee_data))
    if response.status_code == 200:
        print("Employee created successfully!")
        print(response.json())
    else:
        print("Failed to create employee. Error:", response.text)
except Exception as e:
    print("Error:", str(e))

The error message I encounter when I run the script:

Failed to create employee. Error: {"exception":"frappe.exceptions.PermissionError","exc_type":"PermissionError","exc":"[\"Traceback (most recent call last):\\n  File \\\"apps/frappe/frappe/app.py\\\", line 114, in application\\n    response = frappe.api.handle(request)\\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/api/__init__.py\\\", line 49, in handle\\n    data = endpoint(**arguments)\\n           ^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/api/v1.py\\\", line 42, in create_doc\\n    return frappe.new_doc(doctype, **data).insert()\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 288, in insert\\n    self.check_permission(\\\"create\\\")\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 220, in check_permission\\n    self.raise_no_permission_to(permtype)\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 245, in raise_no_permission_to\\n    raise frappe.PermissionError\\nfrappe.exceptions.PermissionError\\n\"]","_server_messages":"[\"{\\\"message\\\": \\\"User <strong>Guest</strong> does not have doctype access via role permission for document <strong>Employee</strong><br>User <strong>Guest</strong> does not have access to this document\\\", \\\"title\\\": \\\"Message\\\"}\"]","_error_message":"You need the 'create' permission on <strong>Employee</strong>  to perform this action."}

Hi @mohamed13 ,

If the user does not have permission to create an employee, this error occurs. Please find the screenshot below. Give the user the create permission for Employee to resolve the issue.

Thank you Rehan, that’s what I am not understanding, the API credentials were created on the Admin user which has full access to the system, please find the screenshot below:

I have tried creating an employee manually using the same Admin user and it worked just fine.

Hi @mohamed13 ,

Maybe something is going wrong in the steps you are following. Try creating a new user, assigning all roles, generating the API secret, and then trying again.

Thank you @Rehan_Ansari ,

Still same error, can you test from your side by giving the user appropriate permissions to create an Employee, do you get a success response?

Thanks a lot for your help, really appreciate it.

Hi @mohamed13 ,

I checked with the Administrator API key and secret, as well as with a normal user, and I got a successful response. There is another issue in your payload: the date format. Once I corrected that, I got a successful response. Find the screenshot for your reference.

Hi @mohamed13 ,

Instead of this Python script, try using the Postman tool to identify the issue.

This issue only occurs when the authorization you mentioned in the HEADERS is not being considered while making the POST request. Otherwise, it works fine. In the response, you are getting ‘User Guest does not have doctype access,’ which happens only when the authorization in the HEADERS is not being considered.

@Rehan_Ansari Thank you so much for your time and effort,

I will try on postman and update here.

Thanks again.

@Rehan_Ansari I have tried in postman just a simple “GET” and I received the same error:

{“exception”:“frappe.exceptions.PermissionError”,“exc_type”:“PermissionError”,“exc”:“["Traceback (most recent call last):\n File \"apps/frappe/frappe/app.py\", line 114, in application\n response = frappe.api.handle(request)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/api/init.py\", line 49, in handle\n data = endpoint(**arguments)\n ^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/api/v1.py\", line 27, in document_list\n return frappe.call(frappe.client.get_list, doctype, **frappe.form_dict)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/init.py\", line 1726, in call\n return fn(*args, **newargs)\n ^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/utils/typing_validations.py\", line 31, in wrapper\n return func(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/client.py\", line 67, in get_list\n return frappe.get_list(**args)\n ^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/init.py\", line 1990, in get_list\n return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"apps/frappe/frappe/model/db_query.py\", line 115, in execute\n self.check_read_permission(self.doctype, parent_doctype=parent_doctype)\n File \"apps/frappe/frappe/model/db_query.py\", line 512, in check_read_permission\n self._set_permission_map(doctype, parent_doctype)\n File \"apps/frappe/frappe/model/db_query.py\", line 518, in _set_permission_map\n frappe.has_permission(\n File \"apps/frappe/frappe/init.py\", line 1048, in has_permission\n raise frappe.PermissionError\nfrappe.exceptions.PermissionError\n"]”,“_server_messages”:“["{\"message\": \"User Guest does not have doctype access via role permission for document Employee\", \"title\": \"Message\"}"]”,“_error_message”:“No permission for Employee”}

could this be because of my setup? I am running erpnext (packaged by Bitnami) on AWS.

I will try installing erpnext locally on my machine and test it, but how can I overcome this issue, please advice

Thanks again for your assistance.

How do you pass the token in Postman? Can you share the screenshot?

Authorization: token {API_KEY}:{API_SECRET}

Please find the screenshot below:

Please check the setup once, as there are no issues while calling the API.