ERPNext rest-api
Token Authentication Not Works in REST API (ERPNext)
I’m trying to build CRUD operations for ERPNext (cloud hosted) document handling using provided methods.
https://frappeframework.com/docs/user/en/api/rest
I tried Token based authentication method listed there,
got the key and secret from:
All the roles are available for user
- Using Basic token:
> 'Authorization': 'token api_key:api_secret'
request:
const response = await firstValueFrom(
this.httpService.post(
`${host}/api/resource/${docType}?fields=["*"]`,
data,
{
headers: {
Authorization: `token ${key}:${secret}`,
'Content-Type': 'application/json',
},
},
),
);
response:
{
"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 42, in create_doc\\n return frappe.new_doc(doctype, **data).insert()\\n File \\\"apps/frappe/frappe/model/document.py\\\", line 282, in insert\\n self.check_permission(\\\"create\\\")\\n File \\\"apps/frappe/frappe/model/document.py\\\", line 218, in check_permission\\n self.raise_no_permission_to(permtype)\\n File \\\"apps/frappe/frappe/model/document.py\\\", line 239, 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>Customer</strong><br>User <strong>Guest</strong> does not have access to this document\\\", \\\"title\\\": \\\"Message\\\"}\"]",
"_error_message": "Insufficient Permission for Customer (<strong>create</strong>)"
}
it’s look like even the Authentication is provided it is detected as a guest request. is there is any other way to get the expected outcome without using password based authentication it is not align with my use case.
Version info:
- NestJS
- ERPNext v15.15.0
- Frappe Framework v15.17.0