Create new endpoint in tryton HIMS for external use

I am using Tryton for a Hospital Information Management System (HIMS) and want to create a new endpoint to access data externally. However, I am unsure about the best practices, syntax, and approach for this task. Could someone guide me on how to create a new endpoint in Tryton effectively?

Hi Alex and welcome to our community!

I will recomend using an user application for this purpose, you can start by having a look at its documentation:

https://docs.tryton.org/latest/server/topics/user_application.html

If you want to secure the route using some access token, you may be interested in setting an user application key to restrict the access to users not providing a valid authentication token.

There is a working example in the timesheet module, you can see all the routes defined in the routes.py file:

Note that in order to make this code work, you must import the routes file in your __init__.py file, otherwise the server will not know the routes and none of them will work.

If you want to have a look at the code connecting to such web application, you can have a look at the backend.js of the chronos application.

That will give you some basic knowledge on how to achieve your goals. Feel free to drop us another message if you have some more doubts to be resolved.

Cheers!

Thank you for your previous reply!
I have three independent systems (HIMS), which I’ll refer to as one parent system and two child systems. While they share the same codebase, they operate independently of each other. Here’s the desired workflow:

  1. When the parent system performs an internal shipment, the shipment data should be stored in the parent system for the respective child system.
  2. Each child system will have an API endpoint that can manually call the parent system to check if there are any shipments intended for it.
  3. If the parent system has shipment data for a specific child, the API will return all the related shipment details.
  4. The child system will then use the received shipment data to create a supplier shipment within its own system.

This design ensures that while the systems are independent, they can communicate via APIs to synchronize shipment data as required. Could you please guide me on how to design and implement this setup effectively?

@pokoli
I print Hello world to check is that working or not and that works.

from trytond.wsgi import app
from werkzeug.wrappers import Response

 @app.route('/hello', methods=['GET'])
 def hello_world(request):
     return Response("Hello World!", content_type='text/plain')

But when I run the gnuhealth-client that give me the error
ERROR:gnuhealth.rpc:500

can you please tell me why this error occur, my main application is stoped.

Thanks

I can not identify the cause of the error with just the text you posted. You should check the server logs and run client with verbose mode to see which is the cause of the error. You should be able to find a traceback which indicates the problem.

Note that for accessing the endoint you do not need to use the tryton client but you can use any webbrowser or http client. For example, in the system with the child and parent databases you should be able to access the other systems by using the requests library to perform http requestes inside your custom modules

@pokoli
Yes you are right for endpoint I will use webbrowser and http client but for the other part I have to use tryton client but when I try to run the tryton client that give me the error and endpoint is working fine but other system is not working now.

Then just have a look at the server logs as it is clear there is some error on the server.

1 Like