Authentication
Please see the guide on authentication as you need your token to be able to perfom any requests
Documentation
The API is documented here using OpenAPI and Swagger
Headers
You must allways provide the following headers:
- Content-Type
- This header must allways contain
application/vnc.api+json
- This header must allways contain
- Authorization
- This header contains
Bearerfollowed by the token you got from our authentication api
- This header contains
Examples
All examples uses Javascript and the fetch API For the examples we have created a helper function that we will use throughout. The function does not handle invalid responses like 404 (Not found) and similar, its just a helper for the demonstration
async function req(url, token = null, method = "GET", data = {}) {
const baseURL = "https://api.maskon.no";
const response = await fetch(baseURL + url, {
method: method,
credentials: "same-origin",
headers: {
"Content-Type": "application/vnd.api+json",
"Authorization": "Bearer " + token
},
body: method == "POST" ? JSON.stringify(data) : null
});
return response.json();
}
Authenticate
const credentials = {
"user": {
"username": "myusername",
"password": "mypassword"
}
};
var token = "";
req("/auth/user/username/sign_in", null, "POST", credentials).then((response) => {
if (response.authentication.success)
{
console.log("Token", response.authentication.token);
token = response.authentication.token;
}
});
Get information about the current user
req("/account/user", token).then((response) => {
if (response.data)
{
console.log("User", response.data);
}
});