My local function works fine running on
firebase serve --only functions
but once it is deployed to the cloud, I cannot make the same get request to it, using postman. I get the following error on stackdriver:
Unexpected token u in JSON at position 0 at JSON.parse
, and my request returns the following: 400. That’s an error.Your client has issued a malformed or illegal request. That’s all we know.
The Data I send in both local and firebase is a GET
request of type application/json
with a body of:
{
"data": {
"Celebrity_A": "Brad Pitt",
"Celebrity_B": "Angelina Jolie"
}
}
What request is it the firebase function expecting remotely, compared to on local?
Below is the start of my function:
// Main index.ts
exports.funct = functions.https.onRequest(functexp)
// functexp file
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as _request from 'request';
const serviceAccount = require('./credentials.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
export function functexp(request, response) {
console.log(`request`);
console.log(request);
let celebName_A = null;
let celebName_B = null;
if(request !== undefined){
celebName_A = request.body.data['Celebrity_A'];
celebName_B = request.body.data['Celebrity_B'];
console.log(`celebA is ${celebName_A}`)
} etc...
}
rewrites
here. If not, I'd start withcredentials.json
which probably exists locally and not remotely. Note that you don't normally need that; you can just doadmin.initializeApp()
when running in Functions. – GrubstakePOST
request? You don't seeGET
requests with body very often... – Emeliaemelin