I am trying to locally test my callable Firebase cloud function.
I understand that this needs to be a post request and that there needs to be a Content-Type
of application/json
and a data object in the body of the request.
Here is my raw body in the request:
{
"Content-Type": "application/json",
"data": {
"aString": "some string",
}
}
In the response body I get:
{
"error": {
"message": "Bad Request",
"status": "INVALID_ARGUMENT"
}
}
And in the terminal I get:
> {"severity":"WARNING","message":"Request has incorrect Content-Type. "}
> {"severity":"ERROR","message":"Invalid request, unable to process."}
How do I format the body to get the right Content-Type
?
Update:
Seems like the Content-Type
used in Postman must be in the body and not the header:
The rest of the Postman request:
And my cloud function:
// eslint-disable-next-line import/no-unresolved
const functions = require('firebase-functions');
// eslint-disable-next-line import/no-unresolved
const connectyCube = require('connectycube');
exports.createSession = functions.https.onCall(async (data, context) => {
if (context.auth) {
const appId = functions.config().cc.appid;
const authKey = functions.config().cc.authkey;
const authSecret = functions.config().cc.authsecret;
const CREDENTIALS = [
{
appId,
authKey,
authSecret,
},
];
connectyCube.init(...CREDENTIALS);
const getSession = () => new Promise((resolve, reject) => {
connectyCube.createSession((error, session) => {
if (session) {
resolve(session);
}
console.error('FUNCTION ERROR', error)
reject(error);
});
});
const session = await getSession();
return session;
}
return new Error('App authorization error');
});