Devin Carpenter
Devin Carpenter

Reputation: 917

How to call an exported https Firebase Cloud function within Firebase Cloud functions?

I have a function that I call from the clientside currently, and now I also need to call it from Firebase Cloud Functions.

The syntax is for the function I need to call is

exports.querySomeAPI = functions.https.onCall((data)=>{
    //Does work and returns stuff
});

And I call it from the clientside with

var querySomeAPI = firebase.functions().httpsCallable('querySomeAPI');
querySomeAPI({
    data: "data"
}).then(response => {console.log("Query Response is: ", response);});

Since firebase is not defined on my backend, I tried to call it from the serverside with

var querySomeAPI = admin.functions().httpsCallable('querySomeAPI');
querySomeAPI({
    data: "data"
}).then(response => {console.log("Query Response is: ", response);});

and found out that admin.functions() does not exist. So I tried to call it as a normal function with

querySomeAPI({
    data: "data"
}).then(response => {console.log("Query Response is: ", response);});

as well as a few other methods to no avail. I know there has to be a way to call an exported function from within Firebase Functions but none of the methods I've tried so far have worked.

Anyone know how this can be done?

Link for how to call the https callable function on the clientside

Upvotes: 5

Views: 3564

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317362

You're in for a lot of trouble (and unnecessarily larger billing) if you try to go about calling a function directly from another function like this. You're far better off just creating a plain old JS function that both of your Cloud Functions exports can share independently of each other.

See this: Calling a Cloud Function from another Cloud Function

Upvotes: 3

Related Questions