How to consume the Adonis API
Description | API |
Latest Version | N/a |
Release Date | N/a |
Download Path | N/a |
Type | Documentation |
Description
Adonis Web Service is the WCF solution based on JSON standard response/request. It is used to provide CRUD operations and perform actions on Adonis Ecosystem entities
See also Interfaces
Using the API setting up the authentication
Step 1: Define password/API-Key for Adonis_API
Under administrator login open Configurations -> General -> Personal Portal Service and define a password for the "Adonis_API" user.
Step 2: Access Swagger
Under administrator login open Configurations -> General -> Personal Portal Service.
Click "OPEN AIWS API DOCUMENTATION" to explore available API methods via Swagger.
Step 3: Authentication
Under administrator login open Configurations -> General -> Personal Portal Service.
Click "OPEN AIWS API DOCUMENTATION".
Use method GNL_API_AUTHENTICATION with login "Adonis_API" and password defined in step 1 to generate a security token.
Examples
Example: Client for CrewPortalWebServices on C#
Step 1:References in Visual Studio
Add reference to the Adonis Web Service in Visual Studio.
Step 2: Edd endpoint
Add endpoint in client web.config file. Section System.ServiceModel.
<client>
<endpoint behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="ConsumeFromController" contract="CPWebServiceReference.ICrewPortalWebService" name="ConsumeFromController" />
<endpoint behaviorConfiguration="WebBehavior" binding="webHttpBinding" bindingConfiguration="ConsumeFromControllerSecure" contract=" CPWebServiceReference.ICrewPortalWebService" name="ConsumeFromControllerSecure" />
</client>
Step 3:Call methods
Call the service methods.
You could do this in different ways. In this example we consume service via ChannelFactory. For better flexibility you could use our class CPServiceWrapper.cs
public class CPServiceWrapper
{
public CPServiceWrapper(){}
private bool isSecureConnection(string serviceURL)
{
return (serviceURL.Substring(0, 5)) == "https";
}
private ChannelFactory<ICrewPortalWebService> createChannelFactory(string serviceURL)
{
ServicePointManager.ServerCertificateValidationCallback = (snder, cert, chain, error) => true;
var factory = new ChannelFactory<ICrewPortalWebService>(isSecureConnection(serviceURL) ? "ConsumeFromControllerSecure": "ConsumeFromController");
foreach (var behavior in factory.Endpoint.EndpointBehaviors)
{
WebHttpBehavior web = behavior as WebHttpBehavior;
if (web != null)
web.DefaultOutgoingRequestFormat = System.ServiceModel.Web.WebMessageFormat.Json;
}
factory.Endpoint.Address = new EndpointAddress(serviceURL);
return factory;
}
public string GNL_API_AUTHENTICATION(string login, string password, int lifeTime, string serviceURL)
{
try
{
using (var factory = createChannelFactory(serviceURL))
{
var channel = factory.CreateChannel();
var requesAPIAuthentication = new RequestAPIAuthentication ();
requesAPIAuthentication.Login = login;
requesAPIAuthentication.Password = password;
requesAPIAuthentication.LifeTime = lifeTime;
var response = channel. AUTHENTICATION (requesAPIAuthentication);
if (response != null && response.Authentication_Approved)
{
return response.Authentication_Token;
}
if (response != null && !response.Authentication_Approved)
{
return response.Authentication_ReasonDenied;
}
return String.Empty;
}
}
catch (Exception e)
{
return e.Message;
}
}
}
And generate token using CPServiceWrapper class:
String token = new CPServiceWrapper().GNL_API_AUTHENTICATION("Adonis_API", password, TokenLifeTime, serviceURL);
Example: Call AdonisWebServices using jQuery.
When generate security token browser side you MUST use https connection for security reasons. Rest of methods you could call via http.
Example of generate security token:
var requestAPIAuthentication = new Object();
requestAPIAuthentication.Login = "Adonis_API";
requestAPIAuthentication.Password = "password";
requestAPIAuthentication.LifeTime = 1200;
$.ajax({
url: $('#CPServiceURL').val() + "/GNL_API_AUTHENTICATION ",
data: '{"credentials":' + JSON.stringify(requestAPIAuthentication) + '}',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
cache: false,
async: true,
success: function (data) {
...
},
error: function (xhr, textStatus, error)
{
console.log("Error: " + error.toString());
}
});
An example how to consume DB views using GNL_APMCrewListViews
The method GNL_APMCrewListViews returns the result of any given view defined in the APM database.
In addition, it is possible to define additional query or filter parameters.
Example:
See below the example of a customer asking to return the position profile:
The idea is to create a view that returns the following information based on the information found in the position requirements profile. (This could be a view returning the current crew list)
For example view vProfilePositionRequirements.
Then, use the GNL_APMCrewListViews method to call the view and add any parameters.
For example, Return all Requirements for the General Manager on the vessel with IMO nr 123456789