How to Use Endpoints

The following is our recommended method to use the User Portal API in your custom pages.

Since the User Portal uses AngularJS, we recommend using $http

 

Step 1: Inject $http into your controller

(function() {
'use strict';
angular
.module('app.M1DashboardController')
.controller('MyController', MyController);

MyController.$inject = ['$http']; // inject $http

function MyController($http) { // $http is an argument to controller fn
/* CODE HERE */
}
})();

 

Step 2: Create HTTP request

You can use a generic format for your requests or you can use a specific format depending on the method you're using.

 

Generic Format

This format can be used for any type of request.

var req = {
method: /* request method here, ie "POST" */,
url: /* endpoint here, ie "/tenant_read" */,
headers: { /* makes sure everything is returned in JSON format */
'Content-Type': 'application/json'
},
params: /* dict of path params here, they will automatically be URL-encoded for you */,
data: /* dict of body params here */
}

$http(req).then(function(res) {
/* handle response here */
}, function(err) {
/* handle error here */
});

 

GET Format

var params = {
headers: {"Accept":"application/json"}, /* makes sure everything is returned in JSON format */
params: /* dict of path params here, they will automatically be URL-encoded for you */
}
$http.get(<endpoint, ie "/tenant_read">, params).then(function(res) {
/* handle response here */
}, function(err) {
/* handle error here */
});

 

POST Format

var data = /* dict of body params here */
var options = {headers: {"Accept":"application/json"}} /* makes sure everything is returned in JSON format */

$http.post(<endpoint, ie "/tenant_update">, data).then(function(res) {
/* handle response here */
}, function(err) {
/* handle error here */
});