How do I pass this onRequest
function to onCall
? I am working from my localhost with emulators. Could someone give me some guidance, I have tried to follow the documentation of functions.https.onCall but I can’t understand if I have to do any previous step.
export const getFileInformation = functions.https.onRequest( (req, res) => {
return cors( req, res, () => {
const urls = [
`url1`,
`url2`,
`url3`
];
const urlsCalls: any[] = [];
const resultados: any[] = [];
urls.forEach( url => {
urlsCalls.push(axios.get(url));
});
Promise.allSettled(urlsCalls)
.then( response => {
response.map( (element: any) => {
const item = element.value.data;
resultados.push(item);
});
console.log(resultados);
res.json(resultados);
})
.catch( error => {
console.log(error);
});
} );
});
I’m trying something as simple as this:
export const getFileInformation2 = functions.https.onCall( (data, context) => {
return { msg: 'Hello from Firebase!' };
});
But I get the following error:
{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
How should I address an onCall
function?
2
Answers
Lo resolvĂ asi:
index.ts
Luego ejecuto emulators:
Luego lo llamo desde mi frontEnd:
component.ts
HTTPS Callable functions must be called using the POST method, the Content-Type must be
application/json
, and the body must contain a field calleddata
for the data to be passed to the method.See sample body:
When pasting the URL directly to a browser it is called using the
GET
method which returns an errorRequest has invalid method. GET
and the reason you’re getting{"error":{"message":"Bad Request","status":"INVALID_ARGUMENT"}}
is you’re not passing the required field which isdata
on your request body.You can call a
https.onCall
using curl or Postman.Sample call using curl:
For more information, you may check :