API
For the technical staff; mition is built entirely from API's, there is literally nothing you can't do through APIs. The backend APIs are also only visible to users who are authenticated.
The API (Application Programming Interface) is a set of functions that allows your IT team to read and edit all information stored within your Mition database.
As Mition itself is a front end web application, it uses all these API's already to deliver all of the functionality you see / use in Mition on a daily basis. For this reason we can state "everything" is available via API.
The API requires a user to be authenticated to be able to access the API and specifically that user needs to be in a group that has access to the specific controller that is being called.
A good example is if you wanted to create/use your own website (not inside of Mition) using your mition system to authenticate the users and store the users core details. Add calls from your website to your mition API and authenticate the user and even update their details, the user would have access to the mition system. If you wanted a user to be able to add a webpage, then you would need to ensure that the user has the same access in your mition site.
We have created a really nice feature to expose all of the API's and our team uses this same technology to build our system. If you would like more examples please contact us.
var myurl = 'https://formition.com/'
//Get Login Data Model
Utilities.apiGet(`${myurl}api/Website/GetModel?datasetname=Login`).then(response => {
if (response.data.success) {
//add our data
var userlogin = response.data.dataobject;
userlogin.username = this.state.username; //from your system
userlogin.password = this.state.password; //from your system
Utilities.apiPost(`${myurl}api/Login/AuthenticateUser`, userlogin ).then(response => {
if (response.data.success) {
//do something with response.data.object here
this.setState({ data: response.data.dataobject , errorResponse: false, messages: response.data.message + Utilities.timestamp(), loading: false });
} else {
console.log(`Post failed ` + response.data.message);
this.setState({ errorResponse: true, messages: response.data.message + Utilities.timestamp(), loading: false });
}
});
}
});
Authentication / CORS
If you want to call this API and use authentication / cookies, then you need to solve the issue with CORS. Email the url/s you want to be accessing the API from to support@mition.com.au and we will action this for you.
Many of our functions in the API use Utility ApiGet and ApiPost,
these are tried and tested in the field and work pretty well, so if you would like to copy these for your system feel free.
import React from 'react';
import axios from 'axios';
export class Utilities extends React.Component {
//get
static apiGet(url) {
return axios.get(`${url}`, { credentials: "same-origin" })
.catch(error => {
// handle error
var e1 = {
data: {
success: false,
message: error.message,
dataobject: {}
}
};
var urltmp = '' + url;
if (urltmp.includes('api/Error/LogError') || urltmp.includes('api/Error/BlankLog')) {
//prevent a recursive error loop here
throw new Error("An error has occured in apiGet = network is down");
}
else {
try {
this.errorLog("apiGet", `${url} ${error.message}`);
}
catch {
console.log('failed to log error back to server');
}
}
return e1;
}).then(data => {
//return data
return data;
});
}
}
//post
static apiPost(url, data) {
return axios.post(`${url}`, data, { credentials: "same-origin" })
.catch(error => {
// handle error
var e1 = {
data: {
success: false,
message: error.message,
dataobject: {}
}
};
var urltmp = '' + url;
if (urltmp.includes('api/Error/LogError') || urltmp.includes('api/Error/BlankLog')) {
//prevent a recursive error loop here
throw new Error("An error has occured in apiPost = network is down");
}
else {
try {
this.errorLog("apiPost", `${url} ${error.message}`);
}
catch {
console.log('failed to log error back to server');
}
}
return e1;
}).then(data => {
// return data
return data;
});
}
//error log
static errorLog(module, message) {
Utilities.apiGet(`api/Error/BlankLog`)
.then(response => {
var returnresult = response.data.dataobject;
returnresult.message = message;
returnresult.module = module;
returnresult.url = window.location.href;
var browser = this.Browser();
returnresult.browser = browser.name;
returnresult.browserVersion = browser.version;
returnresult.operatingSystem = browser.os;
try {
//log this error in the backend database
Utilities.apiPost(`api/Error/LogError`, returnresult);
}
catch (e) {
console.log('unable to log error: ' + e.message);
}
});
}
}
Powered by mition