Doctype.save() not working unless I login everytime before calling the API

I created an API in the backend which is being called from both the ERP Frontend (javascript file), and also from a mobile app (or postman).
The backend API fetches the doctype with frappe.get_doc(), makes a couple changes to it and then persists the changes with doctype.save().
When I call this backend API from the ERP Frontend, it works properly everytime and the changes get persisted.
When I call the backend API from the mobile app (or postman), the API does get called properly and everything executes properly except for doctype.save(). Sometimes this save() call works and sometimes it does not work (although it never throws an error).

I realized that using the REST API from postman, if I always call the ERP’s login authentication (using password based authentication) every single time right before calling the backend API, then the doctype.save() function always works. If I don’t always call it but keep using the same cookie that was generated from the authentication call to the backend API call, then the doctype.save() function only sometimes works.

Whenever the doctype.save() function works, I can visually see in the bottom of the doctype the recent changes made to it.

I want to avoid making authentication calls to the ERP every single time I want to call one of the ERP’s API functions and instead use the cookie as it is intended. Does anyone have an idea what might be causing this issue?

Thanks

1 Like

I am having the same issue… have you sorted it out ??

instead of cookies why don’t you use APIKEY and SECRETKEY. I am using that for my third-party integration and working fine.

I have tried this way. the first time it works fine and after that, it completes the whole process but does not save it actually. now I am trying to enqueue it. may it will solve the issue