Reputation: 687
So I've a scenario where when I open the firebase function's url - https://us-central1-geochatterthing.cloudfunctions.net/getWall
I get the below error:
{"error":{"status":"INVALID_ARGUMENT","message":"Bad Request"}}
Also, my getWall functions in Cloud Functions look like the below image.
And below is the link to the api-http.js file:
https://gist.github.com/shubham6996/53cea6696b6d565b7f1ffce53bdaabf4
UPDATED QUESTION:
This function gets called from my React Native Application using the below code:
const wallFunc = firebase.functions().httpsCallable('getWall');
let result = await wallFunc({size: 15});
And when I check the output of result
using below code:
console.log("Show result = "+JSON.stringify(result, this.getCircularReplacer()));
getCircularReplacer = () => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};
And the above code shows me below output in the console:
Show Result = {"data":{"docs":[{"sort":[1530702073924],"id":"04dhcfzDZbNLZoekfhl3"}],"hits":1}}
Here "id": 04dhcfzDZbNLZoekfhl3
is the id of a document fetched from the Firebase database collection. But I want to be able to fetch data of every document from that collection instead of just one document.
Also, in the beginning the error I mentioned of "status":"INVALID_ARGUMENT" , I have found something to this error:
If the client trigger is invoked, but the request is in the wrong format, such as not being JSON, having invalid fields, or missing the data field, the request is rejected with 400 Bad Request, with an error code of INVALID_ARGUMENT.
source: https://firebase.google.com/docs/functions/callable-reference
And in my application, when I call the callable function using
const wallFunc = firebase.functions().httpsCallable('getWall');
let result = await wallFunc({size: 15});
I do pass size as a parameter here but I don't know if I'm missing something or not here.
And in the api-http.js file, in this file at line 36 it shows that data has 2 objects size and from whereas I'm only passing size parameter.
P.S. - I might be wrong in explaining my problem here because I'm actually redesigning this Application. So I'm confused about the right approach here.
Upvotes: 1
Views: 1038
Reputation: 83058
Apparently you are mixing up Callable Cloud Functions and HTTP Cloud Functions.
When you call a Cloud Function directly via an URL (https://us-central1-geochatterthing.cloudfunctions.net/getWall) it means this Cloud Function is an HTTP one.
But it seems from the Cloud Function code (_firebase.functions.https.onCall()
) that it is a Callable one.
Therefore you should call it the way it gets called from your React Native application (cf. the code in your question) and not through an URL. See also this specific section of the documentation: https://firebase.google.com/docs/functions/callable#call_the_function
Upvotes: 2