REST API - Version 4

Good day

I am looking at connecting to ERPNext/Frappe via the REST API. I am looking at the following documentation: https://frappe.io/help/rest_api. I have not been able to get the login functionality working. If I call domain- ‘/api/resource/DocType’ in a normal web browser it gives me an error. But if I log on in the browser open another tab and call the same link I then get a list of doc types. So obviously the API is working but you have to be logged in correctly which is great.

The issue now comes in when I use code to connect I cannot call ‘/api/resource/DocType’ , it just gives me an error because I am not logged in. So I must first log in so I call ‘/api/method/login’ with my username and password, and it just gives me an Internal Server Error.

Can anyone advise me how to login using the API to then be able to make use of the resources API.
Also is V5 API going to change much fro the Version4 API, just wanting to decide which one to develop in.

Thanks All

There is no change in API between version 4 and 5.

Also, to login, try sending a POST request to ‘/’ with the data,
cmd=login&usr={username}&pwd={password}

1 Like

Thanks will give that a try. Have been able to use the following in the terminal:
curl http://domain/api/method/login -XPOST -d “usr=user&pwd=password”

And it logs in fine, but when I try set it up in an ESB it doesn’t like the parameters. The main issue seems to be around the need for an @ in the username. Will try a few other things and let you know if I was succesful.

Glad v4 and v5 not different so I can develop on v4 and upgrade to v5 when it is stable.

You mean Enterprise service bus - Wikipedia?

Also, v4 and v5 are not different in access patterns but there are field name changes in lot of places.

Fieldname changes are at,

https://github.com/frappe/erpnext/blob/develop/erpnext/patches/v5_0/rename_table_fieldnames.py

https://github.com/frappe/erpnext/blob/develop/erpnext/patches/v5_0/rename_total_fields.py

Yes, exactly I am using an enterprise service bus to connect to Frappe ERPNext, and in the ESB you configure your API connectivity. Now normally when using an ESB you actually pass your security with the request, so you pass the certificate information or even a basic username and password so it first authenticates and then performs your request.

But with REST and the Frappe setup you first pass a login request keep the session open or store cookies and then perform your various transactions requests. The ESB is having an issue passing the @ sign in a format that frappe understands. I have tried ASCII, unicode and used the various escape characters to igore certain chars yet frappe either does not recognise the username or the ESB does not like the request string.

Do you know anyone that has used an ESB to connect to the Frappe REST framework?

Thanks for the field name changes that is easy enough to map the changes on the ESB when I do upgrade to V5. (One of the advantages of using an ESB.)

I had used cookiejar in CURL to make it work

http://nayarweb.com/blog/2014/cookie-and-cookie-jars-with-rest-api/

you have to url encode it. Try replacing it with %40

Thanks, I have been trying various ways of URL encoding. I put %40
previously and the ESB system then gives an issue that it tries to do
various conversions on the %40. So been looking at various escape chars to
ignore the %40.
Will let you know if I can get it to work.

Regards

Wesley Walford