I am attempting to call a Firebase Function from my Flutter project. In my pubspec.yaml file I have imported the functions import: cloud_functions: ^0.4.0+2. I have also set up all the firebase configurations as I have a working connection to the firestore database from my app. I then created and deployed a Firebase Function in javascript as follows:
exports.addEventToCalendar = functions.https.onRequest((request, response) =>
const eventData = {
eventName: request.body.eventName,
description: request.body.description,
startTime: request.body.startTime,
endTime: request.body.endTime
};
//more code using these variables
}
I have successfully deployed this function to Firebase and have successfully ran and tested it in the Google Developer Console with the following JSON data:
{
"eventName": "Firebase Event",
"description": "This is a sample description",
"startTime": "2019-07-18T10:00:00",
"endTime": "2019-07-18T14:00:00"
}
So I know this function works.
Now when I try to call this on my Flutter App using this method:
void _addToCal() async {
try {
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'addEventToCalendar',
);
dynamic resp = await callable.call(<String, dynamic>{
"eventName": "Flutter Event",
"description": "This is a sample description",
"startTime": "2019-07-15T10:00:00",
"endTime": "2019-07-15T14:00:00"
});
} catch (e, s) {
print(e);
print(s);
}
}
I get an Instance of 'CloudFunctionsException' error.
On the Firebase side, I look into the logs of the function and see several errors including: TypeError: Cannot read property 'data' of undefined.
Thanks for any help as I am new to Firebase and Cloud Functions.