So my swift code right now to call the cloud functions this:
let sendEmail_CloudFunction = Cloud(functionJobName: "sendEmail", arguments: myParameters)
sendEmail_CloudFunction.runFunction() { result in
switch result {
case .success(let response):
print("Response from cloud function: \(response)")
case .failure(let error):
assertionFailure("Error calling cloud function: \(error)")
}
}
And the node.js cloud function is this:
var args = request.params.arguments
var mailTemplateName = args.mailTemplateName
var mailSubject = args.mailSubject
var mailFromAddress = args.mailFromAddress
var mailRecipient = args.mailRecipient
var mailVariables = args.mailVariables
var mailReplyTo = args.mailReplyTo
var mailAttachmentName = args.mailAttachmentName
const mailgun = require("mailgun-js");
const DOMAIN = 'xxxxxx';
const mg = mailgun({apiKey: 'key', domain: DOMAIN});
const data = {
from: mailFromAddress,
to: mailRecipient,
subject: mailSubject,
template: mailTemplateName,
text: 'Testing some Mailgun mail!',
'h:X-Mailgun-Variables': mailVariables
};
mg.messages().send(data)
.then((res) => {
console.log(res);
console.log(`************************* Sending Mail - console.log - ${JSON.stringify(res)}`);
return res;
})
.catch((err) => {
console.error(err);
// console.log(`************************* Sending Mail - console.log - ${JSON.stringify(err)}`);
return err;
});
The return res is this format:
{"id":"<[email protected]>","message":"Queued. Thank you."}
But from the error, it looks like parse is expecting a ‘result’ : Int.
I have tried returning { result : 1} as JSON and returning just the result above, plus returning the result above with the result property added to the JSON, but none seem to work.
I guess the question is, what is parse expecting, or do I define what the response is, like when I used dataTaskPublisher and .decode with my own response struct.
I hope that helps to clarify my. question.
Thanks for the help!!