Nil return in Parse Cloud function












-1














I am trying to implement a Parse cloud function that utilizes the Mailgun API validation method for an email address. I am obviously doing something wrong as when I call this method from objective-c I get nil back, but the cloud log (console.log) shows that the method is executing correctly - just not returning any value. I am pretty new to async/Promise thinking in Javascript so I am wondering if anyone can see where I go wrong here.



My cloud function implemmented in my node.js Parse Server is:



Parse.Cloud.define('validateEmail', async(request) => {

var mailgun = require('mailgun.js');

var mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY,
public_key: process.env.MAILGUN_PUBLIC_KEY
});

mg.validate.get(request.params.email, {useMasterKey: true}).then(data => {
console.log(data);
return Promise.resolve(JSON.stringify(data));
})
.catch(err => {
console.log(err);
return Promise.resolve(error);
});
})


the cloud function is called from objective-c code as:



 [PFCloud callFunctionInBackground:@"validateEmail" withParameters:@{@"email":user.email} block:^(NSString *bodydata, NSError *error) {

NSDictionary *body = [NSJSONSerialization JSONObjectWithData:[bodydata dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

NSLog(@"validateEmail : %@", body);
}];









share|improve this question
























  • I recommend you reading cloud code documentation.
    – Freddy
    Nov 24 '18 at 7:35
















-1














I am trying to implement a Parse cloud function that utilizes the Mailgun API validation method for an email address. I am obviously doing something wrong as when I call this method from objective-c I get nil back, but the cloud log (console.log) shows that the method is executing correctly - just not returning any value. I am pretty new to async/Promise thinking in Javascript so I am wondering if anyone can see where I go wrong here.



My cloud function implemmented in my node.js Parse Server is:



Parse.Cloud.define('validateEmail', async(request) => {

var mailgun = require('mailgun.js');

var mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY,
public_key: process.env.MAILGUN_PUBLIC_KEY
});

mg.validate.get(request.params.email, {useMasterKey: true}).then(data => {
console.log(data);
return Promise.resolve(JSON.stringify(data));
})
.catch(err => {
console.log(err);
return Promise.resolve(error);
});
})


the cloud function is called from objective-c code as:



 [PFCloud callFunctionInBackground:@"validateEmail" withParameters:@{@"email":user.email} block:^(NSString *bodydata, NSError *error) {

NSDictionary *body = [NSJSONSerialization JSONObjectWithData:[bodydata dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

NSLog(@"validateEmail : %@", body);
}];









share|improve this question
























  • I recommend you reading cloud code documentation.
    – Freddy
    Nov 24 '18 at 7:35














-1












-1








-1







I am trying to implement a Parse cloud function that utilizes the Mailgun API validation method for an email address. I am obviously doing something wrong as when I call this method from objective-c I get nil back, but the cloud log (console.log) shows that the method is executing correctly - just not returning any value. I am pretty new to async/Promise thinking in Javascript so I am wondering if anyone can see where I go wrong here.



My cloud function implemmented in my node.js Parse Server is:



Parse.Cloud.define('validateEmail', async(request) => {

var mailgun = require('mailgun.js');

var mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY,
public_key: process.env.MAILGUN_PUBLIC_KEY
});

mg.validate.get(request.params.email, {useMasterKey: true}).then(data => {
console.log(data);
return Promise.resolve(JSON.stringify(data));
})
.catch(err => {
console.log(err);
return Promise.resolve(error);
});
})


the cloud function is called from objective-c code as:



 [PFCloud callFunctionInBackground:@"validateEmail" withParameters:@{@"email":user.email} block:^(NSString *bodydata, NSError *error) {

NSDictionary *body = [NSJSONSerialization JSONObjectWithData:[bodydata dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

NSLog(@"validateEmail : %@", body);
}];









share|improve this question















I am trying to implement a Parse cloud function that utilizes the Mailgun API validation method for an email address. I am obviously doing something wrong as when I call this method from objective-c I get nil back, but the cloud log (console.log) shows that the method is executing correctly - just not returning any value. I am pretty new to async/Promise thinking in Javascript so I am wondering if anyone can see where I go wrong here.



My cloud function implemmented in my node.js Parse Server is:



Parse.Cloud.define('validateEmail', async(request) => {

var mailgun = require('mailgun.js');

var mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY,
public_key: process.env.MAILGUN_PUBLIC_KEY
});

mg.validate.get(request.params.email, {useMasterKey: true}).then(data => {
console.log(data);
return Promise.resolve(JSON.stringify(data));
})
.catch(err => {
console.log(err);
return Promise.resolve(error);
});
})


the cloud function is called from objective-c code as:



 [PFCloud callFunctionInBackground:@"validateEmail" withParameters:@{@"email":user.email} block:^(NSString *bodydata, NSError *error) {

NSDictionary *body = [NSJSONSerialization JSONObjectWithData:[bodydata dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];

NSLog(@"validateEmail : %@", body);
}];






javascript objective-c parse.com parse-server mailgun






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 3:28







Trond Kristiansen

















asked Nov 21 '18 at 21:08









Trond KristiansenTrond Kristiansen

1,3981235




1,3981235












  • I recommend you reading cloud code documentation.
    – Freddy
    Nov 24 '18 at 7:35


















  • I recommend you reading cloud code documentation.
    – Freddy
    Nov 24 '18 at 7:35
















I recommend you reading cloud code documentation.
– Freddy
Nov 24 '18 at 7:35




I recommend you reading cloud code documentation.
– Freddy
Nov 24 '18 at 7:35












1 Answer
1






active

oldest

votes


















0














This was easily fixed once I figured out how to. Here is my working solution:



Parse.Cloud.define('validateEmail',  async (request) => {
var mailgun = require('mailgun.js');

var mg = mailgun.client({
username: 'api',
key: process.env.MAILGUN_API_KEY,
public_key: process.env.MAILGUN_PUBLIC_KEY
});

return mg.validate.get(request.params.email, true).then(data => {
return data})
.catch(err => handleParseError(err));
})





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420495%2fnil-return-in-parse-cloud-function%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This was easily fixed once I figured out how to. Here is my working solution:



    Parse.Cloud.define('validateEmail',  async (request) => {
    var mailgun = require('mailgun.js');

    var mg = mailgun.client({
    username: 'api',
    key: process.env.MAILGUN_API_KEY,
    public_key: process.env.MAILGUN_PUBLIC_KEY
    });

    return mg.validate.get(request.params.email, true).then(data => {
    return data})
    .catch(err => handleParseError(err));
    })





    share|improve this answer




























      0














      This was easily fixed once I figured out how to. Here is my working solution:



      Parse.Cloud.define('validateEmail',  async (request) => {
      var mailgun = require('mailgun.js');

      var mg = mailgun.client({
      username: 'api',
      key: process.env.MAILGUN_API_KEY,
      public_key: process.env.MAILGUN_PUBLIC_KEY
      });

      return mg.validate.get(request.params.email, true).then(data => {
      return data})
      .catch(err => handleParseError(err));
      })





      share|improve this answer


























        0












        0








        0






        This was easily fixed once I figured out how to. Here is my working solution:



        Parse.Cloud.define('validateEmail',  async (request) => {
        var mailgun = require('mailgun.js');

        var mg = mailgun.client({
        username: 'api',
        key: process.env.MAILGUN_API_KEY,
        public_key: process.env.MAILGUN_PUBLIC_KEY
        });

        return mg.validate.get(request.params.email, true).then(data => {
        return data})
        .catch(err => handleParseError(err));
        })





        share|improve this answer














        This was easily fixed once I figured out how to. Here is my working solution:



        Parse.Cloud.define('validateEmail',  async (request) => {
        var mailgun = require('mailgun.js');

        var mg = mailgun.client({
        username: 'api',
        key: process.env.MAILGUN_API_KEY,
        public_key: process.env.MAILGUN_PUBLIC_KEY
        });

        return mg.validate.get(request.params.email, true).then(data => {
        return data})
        .catch(err => handleParseError(err));
        })






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 22 '18 at 16:58









        E_net4 wishes happy holidays

        11.9k63468




        11.9k63468










        answered Nov 22 '18 at 4:27









        Trond KristiansenTrond Kristiansen

        1,3981235




        1,3981235






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420495%2fnil-return-in-parse-cloud-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'