The platform allows you to create custom API methods as a part of your extension and then use them in a web API or scripts in widgets, pages, and business processes. For example, you can create methods for starting a business process, complex data fetching, or set up methods for interaction with an internal or external system. You can create general-purpose methods and use them in different places repeatedly.
To create or edit a method:
- Go to Administration > Extensions.
- Hover the mouse over the extension and click the gear icon.
- Go to the API Methods tab.
- Click Edit. The method editor will open.
- Click the +Add button. In the window that opens, enter the required information.
- Name.* Enter the method name.
- Address.* Select HTTP request method: GET or POST. Specify at what address to access the method.
- Function.* Create a function to execute when getting a request.
- Authorization. Select an authentication type to use when getting a request.
- Internal authentication. When this option is checked, the method can be called in scripts within business processes, in widgets, and forms. At the same time, you cannot call the method from an external system. The user on whose behalf the script is executed must be authorized in ELMA365.
- External authentication. When this option is selected, the method will be available from the external system by a token.
- Asynchronous start. This option allows you to continue your work without waiting for method execution to finish.
- Description. Write a detailed description of the method here.
- Go to the Scripts tab and write the method source code. Use the TypeScript programming language. If you'd like to know more about the basic principles of scrip-writing in ELMA365 , please visit TypeScript SDK Help Center .
- Save and publish the method.
Accessing the Global constant
You can use the Global constant in API methods to access variables inside workspaces and global parameters. But, using such a constant prevents the extension downloading. It means that enabling access to the Global constant in API methods limits the extension export.
To enable the access to the Global constant:
- In the method editor, go to the Scripts tab;
- In the top menu, click Settings;
- In the window that opens, select the Global option.