RapidSoftwareSolutions / RapidAPIConnect_NodeJS

Use RapidAPI blocks from your NodeJS app using this SDK
5 stars 2 forks source link

integration of the rapidapi connector in Node-Red #6

Open hermygithub opened 6 years ago

hermygithub commented 6 years ago

Hi,

i'm trying to integrate the library of the rapidapi connector via the example nodejs code that is generated when using the Google Maps Distance Matrix API https://rapidapi.com/stefan.skliarov/api/GoogleMapsDistanceMatrix/functions/getDrivingDistanceMatrix

i have installed the package(s) and integrated the library in the settings.js of node-red https://nodered.org/docs/writing-functions.html#global-context

functionGlobalContext: { RapidAPI:require('rapidapi-connect') },

when i fetch the rapidapi from the global context via a function node, this works

const RapidAPI = global.get("RapidAPI"); const rapid = new RapidAPI('xxxxxxxxxxxxxxxxxxxxxx' , '/connect/auth/xxxxxxxxxxxxxxxxxxxxxxxxx');

when triggering the code, node-red is going into a blocked state, no response comming

` try {

rapid.call('GoogleMapsDistanceMatrix', 'getDrivingDistanceMatrix', { 
    'apiKey': 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'trafficModel': 'best_guess',
    'units': 'metric',
    'destinations': ['Baasrode, belgium'],
    'origins': ['technopolis mechelen, belgium']

}).on('success', (payload)=>{
     /*YOUR CODE GOES HERE*/ 
     msg.successGDDM = true;
     node.log("msg.successGDDM = true;");
     node.log(payload);
}).on('error', (payload)=>{
     /*YOUR CODE GOES HERE*/ 
     msg.successGDDM = false;
     node.log("msg.successGDDM = false;");
     node.log(payload);
});

} catch(err) { node.log(err); msg.err= err; }`

any idea on how to make such calls via the rapidapi connector for nodejs?

node-v8.1.4-win-x64

node -v v8.1.4

node red version "_from": "node-red", "_id": "node-red@0.17.4", "_integrity": "sha1-CHooGfa1lwAWa+KbBJRq1ArFE9I=",

thx

H

mikilior commented 6 years ago

Hey. Thanks for approaching. We'll look at the issue soon.

zoernert commented 3 years ago

As this issue is still open. Maybe you might have a look at https://github.com/energychain/node-red-contrib-rapidapi a dedicated node to easily work with RapidAPI hosted APIs. You just need to copy your API key, host, and Endpoint URL. Input parameters and results are in msg.payload.