title: How to call an API from Dialog Flow using get method?
body: <p>My question is about the the use of API in <strong>Webhook</strong>. I used this code for calling an external API from my localhost using ngrok. I have tried <a href="https://stackoverflow.com/questions/49744277/using-3rd-party-api-within-dialogflow-fulfillment?noredirect=1&amp;lq=1">Using 3rd party API within Dialogflow Fulfillment</a> as well, but still not working for my case. This is my code -     </p>
  
  <pre><code>'use strict';
  
  var https = require ('https');
  
  const functions = require('firebase-functions');
  
  const {WebhookClient} = require('dialogflow-fulfillment');
  
  const {Card, Suggestion} = require('dialogflow-fulfillment');
  
  process.env.DEBUG = 'dialogflow:debug';
  
  exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) =&gt; {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + 
  JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
  
  function welcome(agent) {
    agent.add(`Welcome to my agent!`);
  }
  
  function fallback(agent) {
   agent.add(`I didn't understand`);
   agent.add(`I'm sorry, can you try again?`);
  }
  
  function get_products(agent){
    var url = 'https://705861b5.ngrok.io/products';
    https.get(url, function(res){
      var body = '';
      res.on('data', function(chunk){
        body += chunk;
      });
      res.on('end', function(){
       var respose_jquery = JSON.parse(body);
       agent.add("Got a response: ", respose_jquery.product_name);
      });
    }).on('error', function(e){
      agent.add("Got an error: ", e);
    });   
  }
  
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('show_products', get_products);
  agent.handleRequest(intentMap);
  
  });
  </code></pre>