Data Source API

This article provides sample API calls for Data Sources in Metric Insights. The following Item functions are covered:

  • /api/data_source: Fetch the list of all Data Sources and their metadata.
  • /api/data_source_sql: List, create, test, and delete SQL Data Sources.
  • /api/data_source_plugin: List Plugin Data Sources and run plugin actions; e.g., refresh the External Report list.
  • /api/data_source_parameter: Query the parameters of a Plugin Data Source.
  • /api/data_source_external_report: List the External Reports (Data Source Objects) of a Plugin Data Source.

Prerequisites:

Table of Contents

  1. Access Admin > System > API Toolkit
  2. List All Data Sources
  3. Configure SQL Data Sources
    1. List SQL Data Sources
    2. Create (Copy) a SQL Data Source
    3. Test a SQL Data Source Connection
    4. Delete a SQL Data Source
  4. Configure Plugin Data Sources
    1. List Plugin Data Sources
    2. Run a Plugin Data Source Action
  5. List Plugin Data Source Parameters
  6. List External Reports for a Plugin Data Source

1. Access Admin > System > API Toolkit

2. List All Data Sources

A GET request to /api/data_source returns all Data Sources (SQL and Plugin) with basic metadata.

  1. Item: data_source
  2. Method: GET
  3. Enter an API Token.
  4. [Run request]

Example Response

{
  "data_sources": [
    { "id": 12, "name": "Sales MySQL", "type": "database", "plugin_name": "" },
    { "id": 18, "name": "Tableau Server", "type": "plugin", "plugin_name": "Tableau" }
  ]
}

Fields Description

Field NameValue TypeDescription
id
integerThe ID of the Data Source.
name
stringThe name of the Data Source.
type
stringThe Data Source type.
plugin_name
stringThe plugin name (for Plugin Data Sources; empty for SQL).

3. Configure SQL Data Sources

3.1. List SQL Data Sources

A GET request to /api/data_source_sql returns the SQL Data Sources and their connection settings.

  1. Item: data_source_sql
  2. Method: GET
  3. Enter an API Token.
  4. [Run request]

Example Response

{
  "data_source_sqls": [
    {
      "id": 5,
      "name": "Sales MySQL",
      "username": "mi_reader",
      "host_name": "db.example.com",
      "port": "3306",
      "database_name": "sales",
      "jdbc_driver": 3,
      "jdbc_string": "",
      "jdbc_to_mysql_format_mask": "",
      "threads_to_utilize_during_data_fetch": 1,
      "use_remote_data_collector": "N",
      "use_visual_editor": "Y",
      "infer_foreign_keys": "N"
    }
  ]
}

Fields Description

Field NameValue TypeDescription
id
integerThe ID of the SQL Data Source.
name
stringThe Data Source name.
username
stringThe database username.
host_name
stringThe database host.
port
stringThe database port.
database_name
stringThe database name.
jdbc_driver
integerThe JDBC driver ID.
jdbc_string
stringThe custom JDBC connection string (if used).
jdbc_to_mysql_format_mask
stringThe JDBC-to-MySQL date format mask.
threads_to_utilize_during_data_fetch
integerConcurrent threads per update trigger event.
use_remote_data_collector
stringWhether data fetch runs on a Remote Agent. ("Y"/"N")
use_visual_editor
stringWhether the visual editor is allowed. ("Y"/"N")
infer_foreign_keys
stringWhether foreign keys are inferred. ("Y"/"N")

3.2. Create (Copy) a SQL Data Source

A POST request to /api/data_source_sql creates a new SQL Data Source.

  1. Item: data_source_sql
  2. Method: POST
  3. ID: Enter the ID of an existing SQL Data Source to use as a template. After entering it, the Request body is pre-filled with that Data Source's settings.
  4. Select JSON Request and modify the request body:
    • To copy an existing Data Source, provide a unique name and a password, and keep the other settings.
    • To point at a different database, also update the relevant connection parameters (host_name, port, database_name, username, password).
  5. Enter an API Token.
  6. [Run request]

3.3. Test a SQL Data Source Connection

A PUT request to /api/data_source_sql/id/<id> with the body {"call": "test_connection"} validates the connection.

  1. Item: data_source_sql
  2. Method: PUT
  3. ID: The ID of the SQL Data Source to test.
  4. Actions: Test Connection.
  5. Enter an API Token.
  6. [Run request]

3.4. Delete a SQL Data Source

A DELETE request to /api/data_source_sql/id/<id> deletes a SQL Data Source.

  1. Item: data_source_sql
  2. Method: DELETE
  3. ID: The ID of the SQL Data Source to delete.
  4. Enter an API Token.
  5. [Run request]

4. Configure Plugin Data Sources

4.1. List Plugin Data Sources

A GET request to /api/data_source_plugin returns the Plugin Data Sources.

  1. Item: data_source_plugin
  2. Method: GET
  3. Enter an API Token.
  4. [Run request]

Example Response

{
  "data_source_plugins": [
    {
      "id": 21,
      "name": "Tableau Server",
      "plugin": "tableau",
      "on_demand_element_creation": "N",
      "allow_edit_ind": "Y"
    }
  ]
}

Fields Description

Field NameValue TypeDescription
id
integerThe ID of the Plugin Data Source (connection profile).
name
stringThe Data Source name.
plugin
stringThe plugin internal name.
on_demand_element_creation
stringWhether on-demand element creation is enabled. ("Y"/"N")
allow_edit_ind
stringWhether the current user can edit this Data Source. ("Y"/"N")

4.2. Run a Plugin Data Source Action

A PUT request to /api/data_source_plugin/id/<id> runs an action against a Plugin Data Source. The action is selected with the call parameter (the Actions drop-down list in the API Toolkit).

  1. Item: data_source_plugin
  2. Method: PUT
  3. ID: The ID of the Plugin Data Source.
  4. Actions / call: Choose one of the actions:
    • refresh_list: Re-fetch the list of the plugin's External Reports.
    • refresh_security_cache: Refresh the external-tool security caches for this Plugin Data Source. Only works for plugins that support row-level security (such as Tableau and Power BI).
    • get_token: Return an access token for the Plugin Data Source. The access_token field will be empty if the plugin does not use OAuth or token-based authentication, or if valid credentials have not been configured for the profile.
    • update_user_role: Sync user roles and licenses with the source system. Only supported by the Tableau plugin.
  5. Enter an API Token.
  6. [Run request]

5. List Plugin Data Source Parameters

A GET request to /api/data_source_parameter returns the parameters configured for the Plugin Data Source.

  1. Item: data_source_parameter
  2. Method: GET
  3. profile: Optionally, enter the ID of the Plugin Data Source (connection profile) whose parameters to retrieve.
  4. Enter an API Token.
  5. [Run request]

Example Response

{
  "data_source_parameters": [
    { "id": 101, "profile": 21, "name": "site", "value": "Sales" },
    { "id": 102, "profile": 21, "name": "api_version", "value": "3.15" }
  ]
}

Fields Description

Field NameValue TypeDescription
id
integerThe ID of the parameter.
profile
integerThe Plugin Data Source (connection profile) ID.
name
stringThe parameter name.
value
stringThe parameter value.

6. List External Reports for a Plugin Data Source

A GET request to /api/data_source_external_report returns the External Reports (Data Source Objects) available from a Plugin Data Source.

  1. Item: data_source_external_report
  2. Method: GET
  3. profile: The ID of the Plugin Data Source (connection profile).
  4. Enter optional parameters:
    • with_url: Select whether to include the External Report URL ("Y"/"N").
    • ids: Restrict to specific External Report IDs.
  5. Enter an API Token.
  6. [Run request]

Example Response

{
  "data_source_external_reports": [
    {
      "id": 8842,
      "name": "Quarterly Sales",
      "external_report": "wb-1234",
      "parent_external_report": "proj-55",
      "parent_id": 880,
      "metadata": {}
    }
  ]
}

Fields Description

Field NameValue TypeDescription
id
integerThe internal ID of the External Report.
name
stringThe External Report name.
external_report
stringThe external (source-system) ID of the report.
parent_external_report
stringThe external ID of the parent object.
parent_id
integerThe internal ID of the parent object.
metadata
objectSource-system metadata for the report.