OpenPlatform / 05. API
Updated: 15. March 2019
Author: Peter Širka

05. API

Notifications

user object can contain notify key with URL for making of notification. Just call this URL with POST method.

// "user" is a user instance object obtained from OpenPlatorm
RESTBuilder.make(function(builder) {
    builder.url(user.notify);
    
    var data = {};
    data.type = 0; // 0: info, 1: success, 2: warning/error
    data.body = 'GitHub flavored __markdown body__';
    data.data = 'A custom data for app'; // obtaining data from notification is very easy in app, just define "OP.on('notify', function(data) {})" on client-side in your app

    builder.post(data);
    builder.exec(console.log);
});

Badges

Each user object contains badge key with URL for making of icon badge. Just call this URL with GET method.

// "user" is a user instance object obtained from OpenPlatorm
RESTBuilder.make(function(builder) {
    builder.url(user.badge);
    builder.exec(console.log);
});

Service Account

OpenPlatform supports common access token for so-called Service Account. Service Account has Super Admin privileges, so it can read apps, users and modify them.

Access Token in x-token header:

x-token    : k9l055zsuuehyta0fz2ua51kfua99fiq8z704bpw
  • if the token is valid the request will be authorized
  • auth mechanism contains a simple protection for attacks of brute force

Allowed API:

You can found all endpoints in controllers/api.js file declared in authorize group.

Events

The events below can be captured on server-side.

Events for Apps

ON('apps.create', function(app) {
    // New app is created
});

ON('apps.update', function(app) {
    // App is updated
});

ON('apps.remove', function(app) {
    // App is removed
});

ON('apps.sync', function(app) {
    // App meta (openplatform.json) is downloaded and synchronized 
});

ON('apps.refresh', function(app) {
    // Some app/apps are refreshed
    // @app {Application} Optional
});

ON('apps.backup', function(users) {
    // All apps will be stored in JSON file on HDD
});

Events for Users

ON('users.notify', function(user, app) {
    // Received some notification 
    // @user {Object} user instance
    // @app {Object} app instance
});

ON('users.badge', function(user, app) {
    // Received badge 
    // @user {Object} user instance
    // @app {Object} app instance
});

ON('users.create', function(user) {
    // New user is created
    // @user {Object} user instance
});

ON('users.update', function(user, type) {
    // User is updated
    // @user {Object} user instance
    // @type {String} optional, can contain "account"
});

ON('users.refresh', function(user) {
    // Some user/users are refreshed
    // @user {Application} Optional
});

ON('users.unread', function(user) {
    // User will obtain email notification about unread notifications/badges 
});

ON('users.backup', function(users) {
    // All users will be stored in JSON file on HDD
});

ON('users.meta', function(meta) {
    // Internal codelist has been changed
    meta.companies;    // Array
    meta.customers;    // Array
    meta.localities;   // Array
    meta.groups;       // Array
    meta.roles;        // Array
    meta.languages;    // Array
    meta.ou;           // Array
});