
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2024 12:27 PM - edited ‎04-08-2024 12:29 PM
I have a Data Source where type is JDBC and Format is Db2 - Universal
The authentication method I use is API Key, so I don't have neither a user nor a password. I only have a token.
If I add the token in the password field, the connection does not work and I get a "JDBC Syntax Error" as log.
I could establish a connection adding the token in the Connection URL properties field, then replacing the ; with a : in the Connection URL field.
Is there any other way to establish this type of connection without expose the Token I have?
 
 
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 12:11 PM
I solved the problem creating a schedule data import and a system properties.
In the Connection URL Parameters field I added a sort of variable. Then I used the pre and post scripts to replace the variable, run the import, then replace the key again.
Pre script
var dataSourceGR = new GlideRecord('sys_data_source');
var DATA_SOURCE_ID = 'YOUR_ID';
var apiKey = gs.getProperty('YOUR_PROPERTY', '');
var connectionURL = '';
var connectionURLParameters = '';
if (apiKey != '' && dataSourceGR.get(DATA_SOURCE_ID)) {
connectionURL = '' + dataSourceGR.getValue('connection_url');
connectionURLParameters = '' + dataSourceGR.getValue('connection_url_parameters');
connectionURL = connectionURL.replace(';${apiKey}', ':apiKey=' + apiKey);
connectionURLParameters = connectionURLParameters.replace('${apiKey}', 'apiKey=' + apiKey);
dataSourceGR.setValue('connection_url', connectionURL);
dataSourceGR.setValue('connection_url_parameters', connectionURLParameters);
dataSourceGR.update();
}
Post Script
var dataSourceGR = new GlideRecord('sys_data_source');
var DATA_SOURCE_ID = 'YOUR_DATA_SOURCE_ID';
var connectionURLParameters = '';
var regex = /apiKey=[a-zA-Z0-9_]*/g;
if (dataSourceGR.get(DATA_SOURCE_ID)) {
connectionURLParameters = '' + dataSourceGR.getValue('connection_url_parameters');
connectionURLParameters = connectionURLParameters.replace(regex, '${apiKey}');
dataSourceGR.setValue('connection_url_parameters', connectionURLParameters);
dataSourceGR.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2024 02:25 PM
except the import admin or admin. rest will not be able to see the token.
else store it in a property and update the datasource record when exectued from scheduled import using pre processing script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 12:11 PM
I solved the problem creating a schedule data import and a system properties.
In the Connection URL Parameters field I added a sort of variable. Then I used the pre and post scripts to replace the variable, run the import, then replace the key again.
Pre script
var dataSourceGR = new GlideRecord('sys_data_source');
var DATA_SOURCE_ID = 'YOUR_ID';
var apiKey = gs.getProperty('YOUR_PROPERTY', '');
var connectionURL = '';
var connectionURLParameters = '';
if (apiKey != '' && dataSourceGR.get(DATA_SOURCE_ID)) {
connectionURL = '' + dataSourceGR.getValue('connection_url');
connectionURLParameters = '' + dataSourceGR.getValue('connection_url_parameters');
connectionURL = connectionURL.replace(';${apiKey}', ':apiKey=' + apiKey);
connectionURLParameters = connectionURLParameters.replace('${apiKey}', 'apiKey=' + apiKey);
dataSourceGR.setValue('connection_url', connectionURL);
dataSourceGR.setValue('connection_url_parameters', connectionURLParameters);
dataSourceGR.update();
}
Post Script
var dataSourceGR = new GlideRecord('sys_data_source');
var DATA_SOURCE_ID = 'YOUR_DATA_SOURCE_ID';
var connectionURLParameters = '';
var regex = /apiKey=[a-zA-Z0-9_]*/g;
if (dataSourceGR.get(DATA_SOURCE_ID)) {
connectionURLParameters = '' + dataSourceGR.getValue('connection_url_parameters');
connectionURLParameters = connectionURLParameters.replace(regex, '${apiKey}');
dataSourceGR.setValue('connection_url_parameters', connectionURLParameters);
dataSourceGR.update();
}