Multiple api call - node.js

I'm trying to build a nodejs app that runs and if statement to query multiple api's to return a result. Example, running yelps api first, if it finds then break, else continue query another api such as google places or white pages api until it finds a result.
I am passing in either a name of a business, address to return a telephone number. the results expected are in json. I am drawing a blank.
ideas?

so the way to achieve this is you should be able to make http req from your server side and when a result comes with a response then you should check that response. If your requested answer is not in it then you should keep on trying other API end points untill u come across with a suitable response..
so here are some npm packages to achieve this simply
http - node js built in package
Axios - here
request - here
try using one of these packages .. I would use axios .. read their doc and try to do it .. It should clear somethings out for you

Related

how to extract token generated by js script (challenge.flood.io)

I am currently studying Gatling for performance testing, I am new to both. Making the task, I have stuck on the step when I need to get a token to pass it to parameter to get to the other page.
The difficulty for me is that the token is absent in the body, it is generated by a script, so I cannot get it with ...check(css(... or check(regex(...
I tryed to get the token by css and regex, getting empty result
.exec(
http("Step 5 page")
.get("${redirection}")
.check(status.is(200))
.check(substring("Step 5"))
.check(css("input[name='challenger[step_id]']", "value").find.saveAs("step_id"))
.check(css("input[name='challenger[step_number]']", "value").find.saveAs("step_number"))
.check(css("input[name='commit']", "value").find.saveAs("commit"))
.check(css("span.token").find.saveAs("one_time_token")))
How can I get the token?
It's pretty clear from this code that this page is performing an extra ajax request to the /code url to fetch the token and then display it in the page.
You'll find the value in there (you can see this HTTP request a few lines below in the Network tab).
Note: in order to learn Gatling you should probably check the Gatling Academy.

(Asana) XML is invalid: Headers are not supported on this surface

I am pretty sure I am using exactly the same code in the following two cases, as I tested it on Postman first.
The first time I tried to create a task from Postman, it has no issue.
The next time I tried to do the same from my NodeJS server, and it shows this error. I tried the client SDK package and manually calling through Axios, both are not working and throwing the same error.
Is the Asana API not callable from NodeJS server?
It turns out the "Headers" does not indicate the Headers sent with the request, but the "Headers" HTML Element inside the rich text field. Ensure there's no h1-h6 element in your html_notes can solve this issue.

node-red wait for async query for http-response

I have REST-endpoint done with node-red which do some async tasks, for example odbc-query to the database.
When I'm resulting query to the http-response. It's just hangs on browser.
Looks like I need forward req and res object to the http-response. But how I do it?
Here is the flow:
[{"id":"a35e6901.509a1","type":"http in","z":"ec714e97.d73b58","name":"","url":"/get","method":"get","upload":false,"swaggerDoc":"","x":287.8571472167969,"y":1660.357177734375,"wires":[["7c116e0a.f8d67"]]},{"id":"98e22918.79bc4","type":"sqldbs","z":"ec714e97.d73b58","mydb":"8df7f8b0.bd44c","querytype":"select","name":"","x":723.5714111328125,"y":1644.6428833007812,"wires":[["de837ef9.5c1cf8"]]},{"id":"7c116e0a.f8d67","type":"function","z":"ec714e97.d73b58","name":"","func":"msq.topic = \"Select * from User\"\nreturn msg;","outputs":1,"noerr":0,"x":469.28570556640625,"y":1613.9286499023438,"wires":[["98e22918.79bc4"]]},{"id":"de837ef9.5c1cf8","type":"http response","z":"ec714e97.d73b58","name":"","statusCode":"","headers":{},"x":922.1428833007812,"y":1677.8570861816406,"wires":[]},{"id":"8df7f8b0.bd44c","type":"sqldbsdatabase","z":"","host":"127.0.0.1","port":"1433","db":"test","dialect":"mysql"}]
You need to make sure that it's the same message object that flows from the http-in node all the way to the http-out node.
This message object will have fields of msg.req and msg.res and the msg.res field will be used by the http-out node to send the response back to the browser.
Any node that takes an input and then forwards it on should preserve these field and not just create a new object for the output. All the built in nodes do this correctly and as should all the published 3rd party nodes. If you find one that does not follow this pattern you should raise a bug with the maintainer.
Your flow looks ok, but I've never used the DB nodes you have so can't comment on those.

Application Insights response code 400 Bad request

when trying to call application insights api service with this url it gave me 400 Bad request
https://api.applicationinsights.io/beta/apps/appID/events/pageViews?timespan=P30D&$filter=contains(pageView/url,'valid-url')&$count=true
appID and valid-url is set correctly and i delete them in this question to make it more easy to read
Is there any issue in using $filter=contains ???
the easiest way to verify this stuff is to use the api explorer, and the demo app:
https://dev.applicationinsights.io/apiexplorer/events
this url shows that startswith works fine:
https://dev.applicationinsights.io/apiexplorer/events?appId=DEMO_APP&apiKey=DEMO_KEY&eventType=pageViews&timespan=P30D&$filter=startswith(pageView%2Furl%2C'http%3A%2F%2Faiconnect')
if you "need" something like contains, you can use $search (which looks across most fields, though, and has its own AND/OR text search logic)
https://dev.applicationinsights.io/apiexplorer/events?appId=DEMO_APP&apiKey=DEMO_KEY&eventType=pageViews&timespan=P30D&$search=%22Customers%2FCreate%22

How to send POST variables with Nipple on NodeJS

I am trying to use nipple to post to an url within my nodejs application, which itself is running on hapi.js
The documentation essentially doesn't seem to spell it out.
(https://www.npmjs.com/package/nipple)
I tried passing it as payload inside options but that, while not returning an error, returns a 400. Can someone provide a correct example doing a post using nipple?
Essentially, I have two variables that I need to send - let's call the var1 and var2.
Thanks!
That link says that the project has been renamed to wreck. On wreck's github, several of the tests are for a post requests, including this one:
https://github.com/hapijs/wreck/blob/master/test/index.js#L68
If you are still scratching your head, you could also try using curl or postman to sanity check your URL, regardless of any nipple/wreck errors. If that also gives you a 400, nipple/wreck may not be the culprit.

Resources