Dear visitor, despite the COVID-19 outbreak, our team continues operating at full speed.

Also, here is the form where you can apply for a special discount and we will contact you with possible options. Stay safe and continue achieving your business goals.

Fill the form
Get Free Trial
Get Free Trial
  1. API reference
  2. Welcome
    1. Component overview
    2. Quick start
    3. System requirements
    4. Troubleshooting
    5. Managing license keys
    6. Migrating from WebDataRocks to Flexmonster
  3. Connecting to Data Source
    1. JSON
      1. Connecting to JSON
      2. Connecting to JSON using Flexmonster Data Server
      3. Data types in JSON
    2. CSV
      1. Connecting to CSV
      2. Connecting to CSV using Flexmonster Data Server
      3. Data types in CSV
    3. Database
      1. Connecting to SQL databases
      2. Connecting to a MySQL database
      3. Connecting to a Microsoft SQL Server database
      4. Connecting to a PostgreSQL database
      5. Connecting to an Oracle database
      6. Connecting to other databases
    4. MongoDB
      1. Introduction to Flexmonster MongoDB Connector
      2. Getting started with the MongoDB Connector
      3. Embedding the MongoDB Connector into the server
    5. Microsoft Analysis Services
      1. Connecting to Microsoft Analysis Services
      2. Getting started with the Accelerator
      3. Installing the Accelerator as a Windows service
      4. Referring the Accelerator as a DLL
      5. Configuring the authentication process
      6. Configuring a secure HTTPS connection
      7. Troubleshooting
    6. Pentaho Mondrian
      1. Connecting to Pentaho Mondrian
      2. Getting started with the Accelerator
      3. Configuring Mondrian roles
      4. Configuring username/password protection
      5. Configuring a secure HTTPS connection
      6. Troubleshooting
    7. Elasticsearch
      1. Connecting to Elasticsearch
      2. Configuring the mapping
    8. Custom data source API
      1. Introduction to the custom data source API
      2. A quick overview of a sample Node.js server
      3. A quick overview of a sample .NET Core server
      4. Implementing the custom data source API server
      5. Implementing filters
      6. Supporting more aggregation functions
      7. Returning data for the drill-through view
    9. Flexmonster Data Server
      1. Getting started with Flexmonster Data Server
      2. Installation guide
      3. Configurations reference
      4. Data sources guide
      5. Security and authorization guide
  4. Security
    1. Security in Flexmonster
    2. Security aspects of connecting to an OLAP cube
      1. Ways of connecting to an OLAP cube
      2. The data transfer process
      3. Data security
      4. Data access management
  5. Configuring report
    1. What is a report
    2. Data source
    3. Slice
    4. Options
    5. Mapping
    6. Number formatting
    7. Conditional formatting
    8. Set the report for the component
    9. Get the report from the component
    10. Date and time formatting
    11. Configuring global options
    12. Export and print
    13. Calculated values
    14. Custom sorting
  6. Integration with frameworks
    1. Available tutorials
    2. Integration with AngularJS (v1.x)
    3. Integration with Angular
    4. Integration with React
    5. Integration with React Native
    6. Integration with Vue
    7. Integration with Python
      1. Integration with Django
      2. Integration with Jupyter Notebook
    8. Integration with R Shiny
    9. Integration with Webpack
    10. Integration with ASP.NET
    11. Integration with jQuery
    12. Integration with JSP
    13. Integration with TypeScript
    14. Integration with RequireJS
    15. Integration with PhoneGap
  7. Integration with charts
    1. Integration with Highcharts
    2. Integration with Google Charts
    3. Integration with FusionCharts
    4. Integration with any charting library
  8. Customizing
    1. Customizing the Toolbar
    2. Customizing appearance
    3. Customizing the context menu
    4. Localizing the component
  9. Updating to the latest version
    1. Updating to the latest version
    2. Release notes
    3. Migration guide from 2.7 to 2.8
    4. Migration guide from 2.6 to 2.7
    5. Migration guide from 2.5 to 2.6
    6. Migration guide from 2.4 to 2.5
    7. Migration guide from 2.3 to 2.4
    8. Migration guide from 2.2 to 2.3
    9. Documentation for older versions
Table of contents

Implementing the custom data source API server

This guide will help you implement your own custom data source API server. To configure your server so it can exchange data with Flexmonster, follow these steps:

Step 1. Set up Flexmonster

Set up an empty component in your HTML page. If Flexmonster is not yet embedded – return to the Quick start guide. Your code should look similar to the following example:

<div id="pivotContainer">The component will appear here</div>
<script src="flexmonster/flexmonster.js"></script>
<script>
var pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
licenseKey: "XXXX-XXXX-XXXX-XXXX-XXXX"
});
</script>

Note that licenseKey is your license or trial key, so replace XXXX-XXXX-XXXX-XXXX-XXXX with an actual key. If you don’t have a license key, get a trial key here.

Step 2. Configure the connection in the Flexmonster report

In report.dataSource, define these parameters to connect to your custom data source API:

<div id="pivotContainer">The component will appear here</div>
<script src="flexmonster/flexmonster.js"></script>
<script>
var pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
    type: "api",
        url: "http://localhost:3400/api/cube",
        index: "data-set-123"
    },

licenseKey: "XXXX-XXXX-XXXX-XXXX-XXXX"
});
</script>

Here, url is the base URL to your API endpoints and index is the identifier of your data set. index will be sent with each request.

At this step, since the back end isn’t configured yet, you won’t see any data in the pivot table if you open it in a browser.

In the next steps, you will find out how to pass the data from your server to Flexmonster using the custom data source API.

Step 3. Create the endpoints to handle POST requests

Flexmonster sends POST requests to the API endpoints in JSON format. After receiving the responses from the server, it visualizes the data in the pivot table or pivot charts. The first step in API implementation is to create the endpoints on your server that will be ready to handle these POST requests.

Note: If Flexmonster Pivot Table is running on a different server, enable CORS.

All requests have index and type properties in the request body. There are 4 types of requests that can be distinguished by the URL path and type value:

  • <url>/handshake (optional) – The first (handshake) request to establish a connection between the client and server sides.
  • <url>/fields – Request for all fields with their types (i.e., meta-object or schema).
  • <url>/members – Request for all members of the field.
  • <url>/select – Request for the data.

We also advise you to check our sample Node.js server or sample .NET Core server that implements Flexmonster’s custom data source API for an example implementation.

Step 4. (optional) Handle the /handshake request

The first request that is sent to <url>/handshake by Flexmonster after configuring the connection is the /handshake request. It is used to establish a connection between the client and server sides and exchange some basic information. The version of the custom data source API implemented by the front end is sent in this request and Flexmonster expects the version of the custom data source API implemented by the back end in return.

/handshake request allows checking whether the server and the client implement the same version of the custom data source API. To receive notifications about the version compatibility, handle the /handshake request the recommended way:

const API_VERSION = "2.8.5";

cube.post("/handshake", async (req, res) => {
    try {
        res.json({ version: API_VERSION });
    } catch (err) {
        handleError(err, res);
    }
});

Note that the /handshake request is optional. Even if the server side does not implement it, the Flexmonster component will proceed to the next request.

Step 5. Handle the request for the data structure

The next request that is sent by Flexmonster is the /fields request and it is sent to <url>/fields. Read more details about the /fields request in the documentation and implement a response to it for your data set.

Custom data source API supports 3 field types: "string", "number", "date". Note, that at least one aggregation has to be supported by the server side for at least one field. For example, a field in the response can have "aggregations": ["sum"] defined:

{
"uniqueName": "Quantity",
"type": "number",
"aggregations": ["sum"]
}

This means that the backend will provide aggregated data for this field and it can be selected as a measure in Flexmonster Pivot Table on the client side.

When the response to the /fields request is successfully received by Flexmonster Pivot Table, the Field List with all available fields is shown. To see it, open the HTML page in a browser.

From now on, the client configured in step 2 starts showing you the data.

Step 6. Handle requests for members

The next request to handle is the request for the field’s members that is sent to <url>/members.

Read more details about the /members request in the documentation and implement a response for your data set.

Now in the Field List, you will be able to select a string field for rows or for columns and retrieve its members.

Step 7. Handle requests for aggregated data

When a field is selected for rows and/or columns and a numeric field is selected for measures in the Field List, the /select request is sent to the endpoint <url>/select.

To handle the /select request, at least one aggregation function must be implemented. For example, start with one aggregation (e.g., "sum") and extend the list of supported aggregations later.

In this step handling of the query.aggs part of the request should be implemented (the /select request can also have query.filter and query.fields, but they can be skipped for now):

{
    "type": "select"
    "index": string,
    "query": {
        "aggs": {
            "values"[]: {
                "field": FieldObject,
                "func": string
            },
            "by": {
                "rows": FieldObject[],
                "cols": FieldObject[]
            }
        }
    }
}

When the response to this kind of the /select request is successfully received by Flexmonster, the pivot table is shown.

What’s next?

You may be interested in the following articles: