Firebase function timeout when calling external api

tate_xy

I'm trying to call an external API in Firebase Functions but i always get a timeout. What can be the issue causing this?

Here is my code

exports.getCountryData = functions.https.onRequest((request, response) => {

const https = require('https');
const options = {
  hostname: "api-football-v1.p.rapidapi.com/v3",
  path: '/fixtures?next=5',
  headers: {
    "x-rapidapi-host": "api-football-v1.p.rapidapi.com/v3",
    "x-rapidapi-key": "my-api-key"
  }
};
  var req = https.get(options, (resp) => {
    let data = '';
    resp.on('data', (chunk) => { data += chunk; });
    resp.on('end', () => {
        var result = JSON.parse(data);
        console.log("Api fetched successfully");

        console.log(result);
   
        response.send({ fulfillmentText: result});
      });
    }).on("error", (err) => { console.log("Error: " + err.message); });
});
tate_xy

It turns out using their Rapid Api url (api-football-v1.p.rapidapi.com/v3) was was resulting in a timeout. Using a direct Api url (v3.football.api-sports.io) with their domain name in it did the trick for me.

Here is my working code.

exports.getCountryData = functions.https.onRequest((request, response) => {

const https = require('https');
const options = {
  hostname: "v3.football.api-sports.io",
  path: '/fixtures?next=5',
  headers: {
    "x-rapidapi-host": "v3.football.api-sports.io",
    "x-apisports-key": "my-api-key"
  }
};
  var req = https.get(options, (resp) => {
    let data = '';
    resp.on('data', (chunk) => { data += chunk; });
    resp.on('end', () => {
        var result = JSON.parse(data);
        console.log("Api fetched successfully");

        console.log(result);
   
        response.send({ fulfillmentText: result});
      });
    }).on("error", (err) => { console.log("Error: " + err.message); });
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Firebase Cloud Functions throws a DNS error when calling an external API

504 timeout in aws EC2 when calling some external api url

SocketException when calling external api

"this" (object) is undefined when calling angularjs function with $timeout

httpsCallable is not a function when calling a Firebase function

clearTimeout doesn't work when the timeout function is calling itself

heroku timeout error H12 when calling API

Calling External API with Javascript

Why is window not working when calling external function from closure?

What happens when calling external an Fortran function with the wrong type of arguments?

Calling Javascript function from external file when loading html page

GestureDetector gesture handler app crash when calling external function

Flutter: PlatformException when calling Firebase Cloud Function on Firebase Emulator

Lambda function timeout on external call

Triggering external API failes on Timeout

Firebase cloud function with fetch request with basic auth to external api

Deployed Firebase Function Cannot Execute HTTP GET to external API?

What is the origin of an external API call made by a firebase function?

Calling external php function in <img>

Calling an External API That Fails Randomly

CORS error when calling Firebase cloud function with httpsCallable()

Angular + firebase: .then() not working when calling function from a service file

Firebase Functions internal error when calling emulator function

Permission Denied when calling a Firebase Cloud Function from Cloud Tasks

Firebase Cloud Function subscribeToTopic timeout

Firebase Function always finished with timeout

I/O timeout exception (java.net.ConnectException) When calling API

Session Timeout keeps calling function in Angular 6

Lambda function calling MediaConvert SDK to describeEndpoints timeout

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive