Outbound Rest Message

DEEPAK KUMAR SI
Tera Contributor

Hi Team,

I need help in scripting part of Data Source.

Requirement :

1) Need to pull data from an external link and that link has tree structure

Endpoint : http://aps:2020/aps/DefaultCollection/ABC/_apis/git/repositories/PersoSQLDatabase/trees/f90a44e8b54a...

HTTP Methods : 

Endpoint : http://aps:2020/aps/DefaultCollection/ABC/_apis/git/repositories/PersoSQLDatabase/items?path=%2FProd...

 

DEEPAKKUMARSI_0-1707191226024.jpeg

 

With current Import sets Data Source Script I am only able to fetch records till 

→asql001shared.json

→bsql002incident.json

 

 I need help in script so that data inside the .JSON should also gets extracted in the import set table (marked in Blue)

REST call: Get the latest repository's URL+
REST call: Get the list of files within the Production folder+  - Till here its working, need help for below steps
Looping on the founded .json files+
REST call: Get the list of databases from the .json file

-----------------------------------------------------------------------

(function loadData(import_set_table, data_source, import_log, last_success_import_time) {
 
     try { 
var r = new sn_ws.RESTMessageV2('PersoSQLManagedInstancePROD', 'Cloud Database Syncronization');
var apiKey = gs.getProperty('Clouddatabase_key');
        r.setStringParameterNoEscape('token', apiKey);
 
 
var tree_response = r.execute();
var tree_responseBody = tree_response.getBody();
var tree_httpStatus = tree_response.getStatusCode();
 
// Get the up-to-date folder tree URL
var tree = JSON.parse(tree_responseBody)._links.tree.href;
r.setEndpoint(tree);
 
// Get the .json file list
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
 
var recev = JSON.parse(responseBody).treeEntries;
 
        for (var i = 0; i < recev.length; i++) {
var knItem = recev[i];
var fname = knItem.relativePath;
var name = fname.replace('.json','');
 
if (name != 'bsql002incident') {
var grKN = new GlideRecord('u_import_cloud_database');
grKN.initialize();
grKN.u_active= true;
grKN.u_name = name;
grKN.insert();
}
}
}
catch(ex) {
var message = ex.message;
}
 
})(import_set_table);
0 REPLIES 0