Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
Call external API in Firebase Cloud Function returns null

I'm trying to call a simple api to currency conversion in Firebase Cloud Function in Typescript, but always it returns 'null'

import { https } from 'firebase-functions';
import * as axios from 'axios';
import * as cors from 'cors';

export const createTransfer = async (amount: number) => {

    https.onRequest((req, res) => {
        cors({origin: true})(req, res, () => {
            const config = {
                headers: {
                  apikey: 'APIKEY',
                },
                params: {
                    to: 'USD',
                    from: 'ILS',
                    amount: amount
                }
              };
            const convert = axios.default.get('https://api.apilayer.com/exchangerates_data/convert', config)
            .then((resp) => {
                res.send(resp.data);
            })
            .catch((error) => {
                res.sendStatus(error);
            });
            return convert;
        });
    });

};

/////// DEPLOYABLE FUNCTION ////////
export const stripeTransferPayment = https.onCall( async (data, context) => {
    const amount = assert(data, 'amount');

    return createTransfer(amount);
});

It should return the converted amount. Where am I doing wrong and how can I solve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like your line return convert; returns the value before it is ever assigned. Try awaiting on your request:

const {data as convert} = await axios.default.get('https://api.apilayer.com/exchangerates_data/convert', config); 
res.send(convert)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!