Skip to main content
Skip table of contents

Connecting to Webgains via SQL

You can use SQL to connect to Webgains in the CData Virtuality Studio or the Code Editor in the Web UI.

Pre-requisites

  • You need the endpoint, the access token and the program id for gaining access to the API.

How to Connect

Before you start retrieving data, you need to run the connector script for Webgains in the CData Virtuality Studio or the Web UI and input your credentials in the following line: 

SQL
CALL SYSADMIN.createConnection(
    name => 'webgains_src',
    jbossCliTemplateName => 'ws',
    connectionOrResourceAdapterProperties => 'EndPoint=https://api.webgains.com/2.0,AccessToken=<AccessToken>
);;
 
 
CALL SYSADMIN.createDatasource(
    name => 'webgains_src',
    translator => 'webgains',
    modelProperties => 'programId=<programId>'
);;

You may optionally add a multi-tenancy table if you wish to access data from multiple accounts in the API. Please, keep in mind, that you have to manually pass the label parameter to the procedures of the API to identify which credentials should be used in the request. If you are not using multi-tenancy, remove the multitenancy_tablename parameter from the model properties, as the default value is not intended to be present in production environments.

Example

SQL
CREATE VIEW webgains.Credentials
AS
SELECT
        '<label_1>' AS label,
        '<EndPoint_1>' AS EndPoint,
        '<AccessToken_1>' AS AccessToken,
        '<programId_1>' AS programId
UNION ALL
SELECT
        '<label_2>' AS label,
        '<EndPoint_2>' AS EndPoint,
        '<AccessToken_2>' AS AccessToken,
        '<programId_2>' AS programId
;;

You may add additional sets using UNION ALL - just make sure labels are unique.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.