0

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?

Chris
  • 99
  • 2
  • 12
  • try to be more elaborative with the question and please provide some code so that we can help.. this seems to be a problem of your call .. but can't say anything until we see some codes – ALPHA Mar 05 '19 at 03:02
  • I’m more so stuck on how to begin writing the call. I want to do three api calls but exit when it finds the right quartz. Any ideas as to how to begin or anywhere you can point me to? – Chris Mar 05 '19 at 03:07

1 Answers1

0

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

ALPHA
  • 1,135
  • 1
  • 8
  • 18
  • this is perfect, with axios, can you pass in api keys? – Chris Mar 05 '19 at 03:34
  • if u r satisfied with the answer please vote and mark it as the answer .. :) – ALPHA Mar 05 '19 at 03:39
  • what do you mean API keys ? u mean for google and white pages api keys ? if so then you should create accounts in google ( I think u already have one and then you will need to register with white pages and then get api key generated for you – ALPHA Mar 05 '19 at 03:42
  • Yes i have the api keys already, what i meant is, is there a method in axios to pass in the api keys as parameters? – Chris Mar 05 '19 at 03:44
  • that depends on the api u are using mate .. so if the API requests your key to be added to your req header then you can do it .. there is a way in axios read the docs. but most cases APIs require API keys to be binded with the req as a parameter so its easy like this www.api.com/v1/api/getData/key=hshdfzwej093urhrlurfhrgrg ..... like wise concatenate to the req just like above – ALPHA Mar 05 '19 at 03:48