ERPNEXT step does not authenticate correctly

I have successfully connected up ERPNEXT.

In steps.erpnext.debug.config object can see that i have the correct url, username and password

aync (events,steps,auth) ==> {
return await require("@pipedreamhq/platform").axios(this, {
url: ${auths.erpnext.base_url}/api/method/frappe.auth.get_logged_user,
auth: {
username: ${auths.erpnext.api_key},
password: ${auths.erpnext.api_secret},
},
})
}

However when i create a step that uses ERPNEXT i get authentication errors.

ErrorRequest failed with status code 401

{
ā€œexc_typeā€: ā€œAuthenticationErrorā€,
ā€œexcā€: ā€œ[ā€œTraceback (most recent call last):\n File \ā€/home/frappe/frappe-bench/apps/frappe/frappe/app.py\ā€, line 59, in application\n frappe.api.validate_auth()\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/api.py\", line 173, in validate_auth\n validate_auth_via_api_keys(authorization_header)\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/api.py\", line 225, in validate_auth_via_api_keys\n validate_api_key_secret(api_key, api_secret, authorization_source)\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/api.py\", line 244, in validate_api_key_secret\n doc_secret = frappe.utils.password.get_decrypted_password(doctype, doc, fieldname=ā€˜api_secret’)\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/utils/password.py\", line 62, in get_decrypted_password\n frappe.throw(_(\ā€œPassword not found\ā€), frappe.AuthenticationError)\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/init.py\", line 438, in throw\n msgprint(msg, raise_exception=exc, title=title, indicator=ā€˜red’, is_minimizable=is_minimizable, wide=wide, as_list=as_list)\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/init.py\", line 417, in msgprint\n _raise_exception()\n File \"/home/frappe/frappe-bench/apps/frappe/frappe/init.py\", line 371, in _raise_exception\n raise raise_exception(msg)\nfrappe.exceptions.AuthenticationError: Password not found\n"]",
ā€œ_server_messagesā€: ā€œ[ā€{\ā€œmessage\ā€: \ā€œPassword not found\ā€, \ā€œindicator\ā€: \ā€œred\ā€, \ā€œraise_exception\ā€: 1}"]"
}
at null.createError (/opt/ee/node_modules/axios/lib/core/createError.js:16:15)
at null.settle (/opt/ee/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/opt/ee/node_modules/axios/lib/adapters/http.js:236:11)
at IncomingMessage.emit (events.js:412:35)
at null.endReadableNT (internal/streams/readable.js:1317:12)
at process.processTicksAndRejections (internal/process/task_queues.js:82:21)

@rodenp just to confirm, have you configured an API key + API secret in ERPNext, and are you entering those as a part of your connected account details?

Hi there,
I would really appreciate some help in resolving the ERPNEXT issue.
Is there anything i can do to help debug the issue?
I can successfully connect and the API key and secret are displayed correctly.
However the ${auths.erpnext.base_url}/api/method/frappe.auth.get_logged_user call fails as illustrated above.
thanks

Hi there @rodenp I’m wondering if you are already following this documentation because it says you need to pass a header like this in your request

headers: {
        'Authorization': 'token api_key:api_secret'
}

Update:
I’ve just tried the same request like this and it worked like a charm using Token Based Authentication!

async (events, steps, auth) => {
 return require("@pipedream/platform").axios(this, {
  url: `${auths.erpnext.base_url}/api/method/frappe.auth.get_logged_user`,
  headers: {
    Authorization: `token ${auths.erpnext.api_key}:${auths.erpnext.api_secret}`
  }
}
});

I just discovered a solution that fixes the problem.
The documentation in ERPNEXT is not always the easiest to follow.

In ERPNEXT there are 2 places to create OAUTH/API details.
The one that i used is not linked to a user and authenticates as we have seen.
However it lacks privileges to perform API functions.
The second version that i just discovered is where you generate API keys for a user.
When i use this method then it works properly.

I’m so sorry for wasting your time @dylburger.
Thanks for everyone in this community for your help.

Please close this ticket.

2 Likes

Great, I’m glad that worked for you. We’ll update our docs to make this more clear!

Thanks @dylburger. Keep up the great work here at pipedream.

Also had this problem. It was fixed by adding an Api key and Secret for the Administrator User (within a company workspace), not using the Api from the ERPnextCloud.

There’s still one problem; I’m trying to import a project and its cards from a Trello board, into the Project/tasks of ERPnext. The PipeDream template trigger I’m using is ā€˜if card is updated’. But I’m not updating any cards, I’m trying to import all of them into a fresh project in ERPnext.

Do I need to set up a Project in ERPnext that matches the board-name of my Trello project? Or can it populate a new project using the Pipedream import of the collection of cards?

Hi @forzunaltd

Glad to hear you were able to solve the authentication problem with ERPnext.

The PipeDream template trigger I’m using is ā€˜if card is updated’. But I’m not updating any cards, I’m trying to import all of them into a fresh project in ERPnext.

That’s correct, all Pipedream triggers are forward facing. They don’t attempt to cycle through all of your past events in a given resource.

Do I need to set up a Project in ERPnext that matches the board-name of my Trello project? Or can it populate a new project using the Pipedream import of the collection of cards?

Nope! You can choose whichever naming convention you’d like. You’ll just need to choose which board syncs to which board in the Pipedream workflow.