When sending {\"identifiant\": \"iJXB5E0PsoKq2XrU26q6\"}
to the below Cloud Function, I cannot get the identifiant
value in the request body and it wil
Unlike a Callable function, the body of a request is not parsed automatically and needs to be parsed before you can use it.
In addition, json(...)
will call end()
internally so you don't need both. Also make sure that you don't call end()
, send()
, json()
, etc. multiple times, as this will lead to errors.
const jsonParser = require('body-parser').json();
exports.meusCandidatos = functions.https.onRequest((req, res) => {
jsonParser(req, res, (err) => {
if (err) {
res.status(500).json({error: err.message});
return; // stop here
}
const identifiant = req.body.identifiant;
if (!identifiant) {
res.status(500).json({error: 'PROBLEMAS NO REQUEST'});
return; // stop here
}
// continue
res.status(200).json({ status: 'ok' });
})
});