User-Defined Extensions
If an additional user-defined action or operation is required in the project, it is possible to extend the existing list of standard operations. TX API contains 10 user-defined extension slots (numbered from 0 to 9) that can be used to implement the required custom logic. Each slot refers to a respective user-defined function that is configured in TranzAxis for the corresponding incoming API interface.
TranzAxis Configuration
Let us assume that the following user-defined function is configured in TranzAxis for the incoming TranzAxis REST API Server Interface (Custom Operations tab):
- Operation number: 0
- UDF description: REST_UDT_1
The program code of this function returns a JSON response with two parameters (of string and boolean types), and echoes the value of the parameter from the request body:
CustomOperation.asd:Operations.CustomOperation0V1.ResponseByStatus_200 rs =
rsFactory.prepareResponse_200();
IJsonDocument json = rs.ensureContent();
json.setStr("text", "Hello, world!");
json.setBool("test", true);
json.setStr("param1_echo", rq.Body.getStr("param_1"));
return rs;
Calling TX API
The custom operation can be called in the following way (function name in URL is used to easily distinguish several operation slots and quickly identify the TranzAxis function being used):
POST
http://tx/v1/custom-operation-0/REST_UDT_1
Example of the request body (passes to TranzAxis one parameter with the param_1 name and Value 123 of string type):
{"param_1": "Value 123"}
TranzAxis returns the following response (according to the code example above):
{
"text": "Hello, world!",
"test": true,
"param1_echo": "Value 123"
}
Single and Multiple Actions
Each extension slot (0-9) can handle one or several actions depending on the project requirements and complexity. To handle multiple actions via one extension slot, it is necessary to add the respective parameter, for example, actiontype, and specify the values for it, for example, action1, action2, etc. This parameter should be passed to TranzAxis as described in the example above. The respective UDF in TranzAxis will receive and process this parameter to perform the actions based on the parameter value.
For complex projects it is recommended to group user-defined actions in dedicated slots, thus making the implementation of the custom logic simpler both in the calling system and in TranzAxis.