Is it possible to query the data using custom JS?

Hello folks,

I’m wondering if there’s a way to use custom JS to query a dataset in a connection?
This would be independent of the query for the widget itself. It would be a separate query.

For example, I’d like to write a query to get the distinct values of a field and display it as a popup in the filter section. So if a user mouses over “Active”, they will see a list of all distinct values that we are labeling as “Active” by running this query on the back and returning this list of values.

Is this possible?

@fernie You can call the Data API end point using JS.

Below is sample custom style that calls the API using API key.

    var f = function() {};
    f.version = "1";
    f.afterDraw = function() {
        var url = ""
        var apikey = "Kasdf132qL5iYh0Sgep7mv591eIwbd0KN26SB5Sc9VRRuh"

        var dsreq = {
            {"type":"SIMPLE","expr":"[manufacturer] as 'manufacturer'"}],
            {"expr":"sum([sodium_mg]) as 'sum(sodium_mg)'"},
            {"expr":"avg([fat_grams]) as 'avg(fat_grams)'"},
            {"expr":"sum(1) as 'Record Count'"}],
          "filters":["[cold_or_hot] in ('C')"],
        var payload = {
          'version': 1,
          'dsreq': JSON.stringify(dsreq),
       // Call the API
            url: url,
            data: payload,
            type: 'POST',
            beforeSend: function (xhr) {
                xhr.setRequestHeader("X-CSRFToken", arc.globals.csrf_token);
                xhr.setRequestHeader("Authorization", 'apikey ' + apikey);
        }).done(function(response) {
            var colNames = response["colnames"]
            var columns = []
            colNames.forEach(function(column) {
              columns.push({"title": column})
           // "response" contains the results of the query.
              data: response["rows"],
              columns: columns
            var params = {
              "request_url": url,
              "request_data": JSON.stringify(payload),

    return f;