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);
});1
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
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛