Server-Side Data Fusion API Call with Node.js

I am able to run this code fine from a client-side app:
$.ajaxSetup({
beforeSend: function(xhr, settings) {
xhr.setRequestHeader('Authorization', "Bearer " + myAccessToken);
}
});
$.ajax(myURL, {
dataType: 'json',
type: 'get',
success: function(data, status) {
dataReturned1(data);
},
error: function(xhr, status, error) {
console.log(xhr);
}
});
The problem comes when I attempt to run this server-side using Node.js, something like this:
var express = require('express');
var app = express();
var fs = require("fs");
var $ = require("jquery");
app.get('/sellsidebuyside', function (req, res) {
// AJAX REQUEST AS ABOVE HERE
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
The error message is:
TypeError: $.ajaxSetup is not a function
From online forums I gather that jQuery was perhaps never designed to run server-side, so this could be the root of my issue. It is suggested to use a standard XMLHttpRequest, but I'm not sure how to configure this to make a cross-domain request using the access token.
Please provide example JS code for a Data Fusion API call which will run server-side with Node.js?
Best Answer
-
Thanks to a consultation with EPAM and some advice from the Boston lab teams, here it is! Note this is just a demo which dumps the result to the console...
var express = require('express');
var app = express();
var q = require('q');
var https = require('https');
app.get('/sellsidebuyside', function (req, res) {
var defer = q.defer();
var referenceID = "1-4297777075";
var myURL = "{instance hostname}";
var myPath = "/datafusion/api/entity/search?limit=1000&dir=asc&parentUrisDirect=http%3A%2F%2Fpermid.org%2F" + referenceID + "&includePredicates=false&includeRelDir=false&parentPredicateFilters=30%7C%7C%7Chttp%3A%2F%2Frdf.thomsonreuters.com%2Frelationship%2FSellSideBuySideOrganization&filterType=and&includeHiddenFields=false";
var access_token = "{your_token_here}";
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var options = {
hostname: myURL,
path: myPath,
port: 443,
method: 'GET',
headers: {'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/json',
'Accept': 'application/json'}
};
var request = https.request(options, function(res) {
console.log(res);
res.setEncoding('utf8');
var body = '';
res.on('data', (chunk) => {
body += chunk;
});
res.on('end', () => {
console.log(body);
defer.resolve(body);
});
});
request.on('error', (e) => {
console.log(e);
defer.reject(e);
});
request.end();
defer.promise.then((result) => {
res.send(result);
}, (error) => {
res.send(error);
});
});
var server = app.listen(8081, function () {
var host = server.address().address;
var port = server.address().port;
console.log("Example app listening at http://%s:%s", host, port);
});0
Answers
-
We don't have example Node.js code on hand, but here are some links that might get you started:
http://stackoverflow.com/questions/19392744/calling-a-web-service-using-nodejs
http://stackoverflow.com/questions/30149327/can-node-js-make-a-restful-service-call
http://stackoverflow.com/questions/5643321/how-to-make-remote-rest-call-inside-node-js-any-curl
https://rapiddg.com/blog/calling-rest-api-nodejs-script
http://stackoverflow.com/questions/16148403/using-node-js-to-connect-to-a-rest-api/16155551#16155551
https://isolasoftware.it/2012/05/28/call-rest-api-with-node-js/
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 687 Datastream
- 1.4K DSS
- 622 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 254 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 276 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 671 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛