Request
Request used to make http requests to Facilio API, Connector API
or External API
.
#
Facilio APIapp.request.invokeFacilioAPI(url, options)
- Is used to call Facilio API. Refer the API Documentation.
Params
Param | Description |
---|---|
url | Facilio API end point. |
options | These are the available config options for making requests. Requests will default to GET if method is not specified. {method: 'GET', headers: {}, params: {}, data: {}} |
Example
let url = "/v2/assets/add";let options = { method: "POST", data: { asset: { name: "Chiller - West Area", category: "Chiller", }, },};app.request .invokeFacilioAPI(url, options) // will return Javascript Promise .then((response) => { let assetId = response.data.result.asset.id; console.log("Asset added successfully. id: " + assetId); }) .catch((error) => { // error in request });
#
Connector APIapp.request.invokeConnectorAPI(connector, url, options)
- Is used to call api’s of OAuth2 Connectors defined in the Connected Apps.
Params
Param | Description |
---|---|
connector | Connector namespace. |
url | API endpoint. |
options | These are the available config options for making requests. Requests will default to GET if method is not specified. {method: 'GET', headers: {}, params: {}, data: {}} |
Example
let connector = "zendesk";let url = "/api/v2/tickets.json"; // calling Zendesk api which configured as OAuth connector in Facilio.let options = { method: "POST", data: { ticket: { subject: "AC not working", description: "The reception are AC seems not working. can you please check?", }, },};app.request .invokeConnectorAPI(connector, url, options) // will return Javascript Promise .then((response) => { let ticketId = response.data.ticket.id; console.log("Ticket added successfully. id: " + ticketId); }) .catch((error) => { // error in request });
#
External APIapp.request.invokeExternalAPI(url, options)
- Is used to call thridparty api’s such as fetching public Weather data or fetching geo location data.
Params
Param | Description |
---|---|
url | API endpoint. |
options | These are the available config options for making requests. Requests will default to GET if method is not specified. {method: 'GET', headers: {}, params: {}, data: {}} |
Example
let url = "https://api.openweathermap.org/data/2.5/weather?q=USA"; // Fetching current weather of United States using OpenWeather API.app.request .invokeExternalAPI(url) // will return Javascript Promise .then((response) => { let weatherData = response.data; // weatherData is - {"coord":{"lon":-122.09,"lat":37.39},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"stations","main":{"temp":280.44,"pressure":1017,"humidity":61,"temp_min":279.15,"temp_max":281.15},"visibility":12874,"wind":{"speed":8.2,"deg":340,"gust":11.3},"clouds":{"all":1},"dt":1519061700,"sys":{"type":1,"id":392,"message":0.0027,"country":"US","sunrise":1519051894,"sunset":1519091585},"id":0,"name":"Mountain View","cod":200} }) .catch((error) => { // error in request });
#
Facilio Function APIapp.request.invokeFacilioFunction(nameSpace, functionName, params)
- Is used to call facilio function.
Params
Param | Description |
---|---|
nameSpace | Namespace of the function. |
functionName | Name of the function |
params | Function parameters |
Example
app.request.invokeFacilioFunction(‘workorder’, ‘fetchWorkorderCompletionRate’, siteId, buildingId) .then((response) => { console.log("Function result", response); }) .catch((error) => { // error in request });