Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • Data Fusion /
avatar image
REFINITIV
Question by tristan.hale · Oct 05, 2016 at 08:04 AM · data-fusionnode-jsajax

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?

People who like this

0 Show 0
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

2 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by tristan.hale · Oct 13, 2016 at 05:43 AM

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);
});
Comment
Tomasz Adamusiak

People who like this

1 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

avatar image
REFINITIV
Answer by Tomasz Adamusiak · Oct 10, 2016 at 11:15 PM

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/

Comment

People who like this

0 Show 0 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
7 People are following this question.

Related Questions

Please share the ppt and links of the ESG Score webcast

Sample oauth token php code

Looking for guidance on utilizing API and confidence scores

Retrieving TRIT relevance & confidence scores within Data Fusion

What is the support for external apps to login with Data Fusion?

  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Electronic Trading
    • Generic FIX
    • Local Bank Node API
    • Trading API
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Intelligent Tagging
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open Calais
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • RDMS
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • Workspace SDK
    • Element Framework
    • Grid
  • World-Check Data File
  • 中文论坛
  • Explore
  • Tags
  • Questions
  • Badges