×

MA!N REST API

Last updated: April 22, 2024

Applications can call the MA!N Rest Service for exchanging data with MA!N.

Installation

The service is created as a self-containing application and therefore it does not need any additional components to be installed.

Files

  1. Choose and/or create a target location for the MainService. Preferably within the Program Files folder of Windows (C:\Program Files).
  2. Unzip the contents of MainServices.zip to the target location.

Change connection string

  1. Open file appsettings.json from the target location in a text editor (e.g. notepad++).
  2. Change the default database connection string to the correct server and database. See screenshot below.

Database changes

The service uses 2 stored procedures which have to be present in the previous defined database.

  1. SPRESTGet
  2. SPRESTPost

The SQL script for these 2 stored procedures can be found in the file “MainRestService Stored Procedures.sql”

Note: The name of the input parameter and the field names of the select result are not allowed to change. Also the order of the fields in the select result is not allowed to change!!! The contents of the select result can be changed according the required needs.

Install the service

  1. Open a command prompt in administrator mode and go to the target location.
  2. Execute from the command line the following commands:
    • sc create MainRestService binPath= “\”\”” DisplayName= “Main REST Service” Start= “delayed-auto”.
    • sc description MainRestService “Facilitates a REST service on the Ma!n Database”.
    • Replace by the location where the MainService is distributed.
  3. Go to services and right click the newly created Main REST Service and open the properties.
  4. Configure the service (Log on account etc.)

Usage

MainServices is a REST service that acts as a interface between a client application and Main. Two types of requests are available:

  1. GetData: Retrieve data from Main.
  2. PostData: Post data to Main.

Getdata

Request

GET http://localhost:5000/api/GetData/Parameters?Parameter=test1&Parameter=test2

The number of parameters is not limited. Extra parameters can be added with “&Parameter=”

Result

The result parameters are:

  1. dataJSON: A string containing the result data in JSON format.
  2. returnMessage: The result message containing result information.
  3. returnCode: The result code
  4. submittedTime: Time of submission of the request.

Swagger JSON file for this command:

{
"swagger": "2.0",
"info": {
"title": "MainServices",
"version": "v2"
},
"paths": {
"/api/GetData/Parameters": {
"get": {
"tags": [
"GetData"
],
"parameters": [
{
"in": "query",
"name": "Parameter",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}

Postdata

Request

POST http://localhost:5000/api/PostData/Parameters?Parameter=test1&Parameter=test2

The number of parameters is not limited. Extra parameters can be added with “&Parameter=”

Result

The result parameters are:

  1. returnMessage: The result message containing result information.
  2. returnCode: The result code.
  3. submittedTime: Time of submission of the request.

Swagger JSON file for this command:

{
"swagger": "2.0",
"info": {
"title": "MainServices",
"version": "v2"
},
"paths": {
"/api/PostData/Parameters": {
"post": {
"tags": [
"PostData"
],
"parameters": [
{
"in": "query",
"name": "Parameter",
"type": "string"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
}
}
}