Page Properties | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
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 . Define and define a password for the "Adonis_API" user.
Step 2: 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 on in step 1 . To to generate a security token.
Step 3: Access Swagger
Under administrator login open Configurations -> General -> Personal Portal Service.
Click "OPEN CREW PORTAL SERVICE AIWS API DOCUMENTATION" to explore available API methods via swaggerSwagger.
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.
Code Block | ||
---|---|---|
| ||
<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
Code Block | ||
---|---|---|
| ||
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:
Code Block | ||
---|---|---|
| ||
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()); } }); |
Example consume DB views via API (AdonisIntegrationWebService)
The method GNL_APMCrewListViews returns the result of any given view defined in the APM database.
In addition it is possible to defined 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 method GNL_APMCrewListViews to call the view and add any parameters
For example Return all Requirements for General Manager on the vessel with IMO nr 123456789
Code Block | ||
---|---|---|
| ||
function ConsumeSQLViewViaAPI() { var request = new Object(); request.Authentication_Token = "…"; request.View = " vProfilePositionRequirements"; request.Filter = "WHERE Position='General Manager' AND IMO='123456789'"; request.Pagination = false; request.RowsByPage = ""; request.Page = ""; $.ajax({ url: "http://localhost/AIWS/AdonisIntegrationWebService.svc/GNL_APMCrewListViews", data: '{"request":' + JSON.stringify(request) + '}', type: 'POST', dataType: 'json', contentType: "application/json; charset=utf-8", async: true, success: function (data) { }, error: function (xhr, textStatus, error) { console.log(error.toString()); } }); } |