Skip to main content

Request

Request methods for calling Connector API, External API, and Facilio Functions.

For standard module data operations (create, read, update, delete), use the Data API methods instead — they are simpler and handle URLs automatically.

Error handling

Async methods may reject with an error, or return an error object in the response. Handle both: use try/catch for rejections and check response.error when present.

Facilio API (Deprecated)#

Deprecated

app.request.invokeFacilioAPI() is deprecated. Use the Data API methods instead:

  • app.api.createRecord() — create records
  • app.api.updateRecord() — update records
  • app.api.fetchRecord() — fetch a single record
  • app.api.fetchAll() — fetch a list of records
  • app.api.deleteRecord() — delete records

These methods are simpler, handle API URLs automatically, and are the recommended way to interact with Facilio module data.

app.request.invokeFacilioAPI(url, options) - Makes a raw HTTP request to the Facilio API. Only use this for endpoints not covered by the Data API methods.


Params

ParamDescription
urlFacilio API end point.
optionsThese 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 API#

app.request.invokeConnectorAPI(connector, url, options) - Is used to call api’s of OAuth2 Connectors defined in the Connected Apps.

Returns — A Promise that resolves with the response as a string. Parse with JSON.parse() if the API returns JSON.


Params

ParamDescription
connectorConnector namespace.
urlAPI endpoint.
optionsThese 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)  .then((response) => {    // Response is a string — parse if JSON    const data = JSON.parse(response);    let ticketId = data.ticket.id;    console.log("Ticket added successfully. id: " + ticketId);  })  .catch((error) => {    // error in request  });

External API#

app.request.invokeExternalAPI(url, options) - Is used to call third-party api’s such as fetching public Weather data or fetching geo location data.

Returns — A Promise that resolves with the response as a string. Parse with JSON.parse() if the API returns JSON.


Params

ParamDescription
urlAPI endpoint.
optionsThese 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)  .then((response) => {    // Response is a string — parse if JSON    const weatherData = JSON.parse(response);    // weatherData: { coord, weather, main: { temp, pressure, humidity }, wind, clouds, ... }    console.log("Temperature:", weatherData.main.temp);  })  .catch((error) => {    // error in request  });

Facilio Function API#

app.request.invokeFacilioFunction(nameSpace, functionName, ...params) — Calls a Facilio Script function. Script functions can declare any primitive params and return type (e.g., Map fetchWorkorderCompletionRate(Number siteId, Number buildingId)).


Params

ParamDescription
nameSpaceNamespace of the function.
functionNameName of the function
...paramsFunction parameters as separate arguments (e.g., siteId, buildingId)

Returns — Object with result.workflow.returnValue containing the function's return value. Use response?.result?.workflow?.returnValue.


Example

const response = await window.facilioApp.request.invokeFacilioFunction(  'workorder', 'fetchWorkorderCompletionRate', 12342, 234243);const returnValue = response?.result?.workflow?.returnValue;// returnValue holds the function result (Map, String, Number, etc.)