ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

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